Class: What::Config
- Inherits:
-
Object
- Object
- What::Config
- Defined in:
- lib/what/config.rb
Constant Summary collapse
- DEFAULTS =
{ 'interval' => 10, 'formatter' => 'json', 'configs' => [], 'module_paths' => [], 'modules' => [] }
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
46 47 48 |
# File 'lib/what/config.rb', line 46 def self.[](attr) @config[attr] end |
.[]=(attr, val) ⇒ Object
50 51 52 |
# File 'lib/what/config.rb', line 50 def self.[]=(attr, val) @config[attr] = val end |
.all ⇒ Object
54 55 56 |
# File 'lib/what/config.rb', line 54 def self.all @config end |
.load(fn) ⇒ Object
13 14 15 16 |
# File 'lib/what/config.rb', line 13 def self.load(fn) load_primary(fn) load_secondary(@config['configs']) end |
.load_primary(fn) ⇒ Object
18 19 20 21 22 |
# File 'lib/what/config.rb', line 18 def self.load_primary(fn) @config = DEFAULTS.merge(YAML.load_file(fn)) @config['base'] ||= File.(File.dirname(fn)) @loaded = true end |
.load_secondary(fns) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/what/config.rb', line 24 def self.load_secondary(fns) return if !fns fns.each do |fn| path = if fn.match(%r(^/)) fn else File.join(@config['base'], fn) end begin opts = YAML.load_file(path) @config.merge!(opts) rescue Exception => e puts "Error loading config file #{path}: #{e}" end end end |
.loaded? ⇒ Boolean
42 43 44 |
# File 'lib/what/config.rb', line 42 def self.loaded? @loaded end |