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.
5 6 7 |
# File 'lib/volay/config.rb', line 5 def logger @logger end |
#mixer ⇒ Object (readonly)
Returns the value of attribute mixer.
5 6 7 |
# File 'lib/volay/config.rb', line 5 def mixer @mixer end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/volay/config.rb', line 5 def end |
Class Method Details
.config_file ⇒ String
Get config file
43 44 45 |
# File 'lib/volay/config.rb', line 43 def self.config_file File.('~/.volay') end |
.get(option) ⇒ Mixed
Get option
22 23 24 25 |
# File 'lib/volay/config.rb', line 22 def self.get(option) ||= {} [option.to_sym] if .key?(option.to_sym) end |
.init_config ⇒ Mixed
Get option
12 13 14 15 |
# File 'lib/volay/config.rb', line 12 def self.init_config File.write(config_file, '') unless File.exist?(config_file) logger.level = get(:log_level) end |
.logger ⇒ Logger
Get logger
52 53 54 |
# File 'lib/volay/config.rb', line 52 def self.logger @logger ||= Logger.new(STDOUT) end |
.mixer ⇒ Object
Initialize mixer for controlling volume
59 60 61 62 63 64 65 66 67 |
# File 'lib/volay/config.rb', line 59 def self.mixer @mixer ||= begin if which('amixer') Volay::Mixer::Alsa.new else fail MixerNotFound end end end |
.set(option, value) ⇒ Object
Set option
33 34 35 36 |
# File 'lib/volay/config.rb', line 33 def self.set(option, value) ||= {} [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
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/volay/config.rb', line 79 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 |