Class: Volay::Config
- Inherits:
-
Object
- Object
- Volay::Config
- Defined in:
- lib/volay/config.rb
Overview
Config class
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#mixer ⇒ Object
readonly
Returns the value of attribute mixer.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.config_file ⇒ String
Get config file.
-
.get(option) ⇒ Mixed
Get option.
-
.init_config ⇒ Mixed
Get option.
-
.logger ⇒ Logger
Get logger.
-
.mixer ⇒ Object
Initialize mixer for controlling volume.
-
.set(option, value) ⇒ Object
Set option.
-
.which(cmd) ⇒ String|NilClass
Cross-platform way of finding an executable in the $PATH.
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/volay/config.rb', line 7 def logger @logger end |
#mixer ⇒ Object (readonly)
Returns the value of attribute mixer.
7 8 9 |
# File 'lib/volay/config.rb', line 7 def mixer @mixer end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/volay/config.rb', line 7 def @options end |
Class Method Details
.config_file ⇒ String
Get config file
45 46 47 |
# File 'lib/volay/config.rb', line 45 def self.config_file File.('~/.volay') end |
.get(option) ⇒ Mixed
Get option
24 25 26 27 |
# File 'lib/volay/config.rb', line 24 def self.get(option) @options ||= {} @options[option.to_sym] if @options.key?(option.to_sym) end |
.init_config ⇒ Mixed
Get option
14 15 16 17 |
# File 'lib/volay/config.rb', line 14 def self.init_config File.write(config_file, '') unless File.exist?(config_file) logger.level = get(:log_level) end |
.logger ⇒ Logger
Get logger
54 55 56 |
# File 'lib/volay/config.rb', line 54 def self.logger @logger ||= Logger.new(STDOUT) end |
.mixer ⇒ Object
Initialize mixer for controlling volume
61 62 63 64 65 |
# File 'lib/volay/config.rb', line 61 def self.mixer raise MixerNotFound unless which('pacmd') @mixer ||= Volay::Mixer::Pulse.new end |
.set(option, value) ⇒ Object
Set option
35 36 37 38 |
# File 'lib/volay/config.rb', line 35 def self.set(option, value) @options ||= {} @options[option.to_sym] = value end |
.which(cmd) ⇒ String|NilClass
Cross-platform way of finding an executable in the $PATH.
Example:
which('ruby') #=> /usr/bin/ruby
which('foo') #=> nil
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/volay/config.rb', line 77 def self.which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable?(exe) && !File.directory?(exe) end end nil end |