Class: What::Config
- Inherits:
-
Object
- Object
- What::Config
- Defined in:
- lib/what/config.rb
Class Method Summary collapse
- .[](attr) ⇒ Object
- .[]=(attr, val) ⇒ Object
- .all ⇒ Object
- .load(fn) ⇒ Object
- .load_primary(fn) ⇒ Object
- .load_secondary(fns) ⇒ Object
- .loaded? ⇒ Boolean
Class Method Details
.[](attr) ⇒ Object
32 33 34 |
# File 'lib/what/config.rb', line 32 def self.[](attr) @config[attr] end |
.[]=(attr, val) ⇒ Object
36 37 38 |
# File 'lib/what/config.rb', line 36 def self.[]=(attr, val) @config[attr] = val end |
.all ⇒ Object
40 41 42 |
# File 'lib/what/config.rb', line 40 def self.all @config end |
.load(fn) ⇒ Object
4 5 6 7 |
# File 'lib/what/config.rb', line 4 def self.load(fn) load_primary(fn) load_secondary(@config['configs']) end |
.load_primary(fn) ⇒ Object
9 10 11 12 13 |
# File 'lib/what/config.rb', line 9 def self.load_primary(fn) @config = YAML.load_file(fn) @config['base'] ||= File.(File.dirname(fn)) @loaded = true end |
.load_secondary(fns) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/what/config.rb', line 15 def self.load_secondary(fns) return if !fns fns.each do |fn| path = if fn.match(/^\//) fn else File.join(@config['base'], fn) end @config.merge!(YAML.load_file(path)) end end |
.loaded? ⇒ Boolean
28 29 30 |
# File 'lib/what/config.rb', line 28 def self.loaded? @loaded end |