Class | Configatron::Configuration |
In: |
lib/configatron/configuration.rb
|
Parent: | Object |
The central class for managing the configurations.
nil_for_missing | [RW] | If nil_for_missing is set to true nil will be returned if the configuration parameter doesn‘t exist. If set to false, default, then a NoMethodError exception will be raised. |
Yields a new Configatron::Store class.
# File lib/configatron/configuration.rb, line 18 18: def configure 19: storage = Configatron::Store.new 20: yield storage 21: unless storage.parameters.empty? 22: @_storage_list << storage 23: load_methods(storage) 24: end 25: end
Used to load configuration settings from a Hash.
# File lib/configatron/configuration.rb, line 28 28: def configure_from_hash(parameters) 29: storage = Configatron::Store.new(parameters) 30: @_storage_list << storage 31: load_methods(storage) 32: end
Used to load configuration settings from a YAML file.
# File lib/configatron/configuration.rb, line 35 35: def configure_from_yaml(path) 36: begin 37: storage = Configatron::YamlStore.new(path) 38: @_storage_list << storage 39: load_methods(storage) 40: rescue Errno::ENOENT => e 41: puts e.message 42: # file doesn't exist. 43: end 44: end
Replays the history of configurations.
# File lib/configatron/configuration.rb, line 47 47: def reload 48: @_storage_list.each do |storage| 49: storage.reload 50: load_methods(storage) 51: end 52: end
All methods are undefined.
# File lib/configatron/configuration.rb, line 64 64: def reset 65: @_storage_list.each do |storage| 66: storage.parameters.each do |k,v| 67: Configatron::Configuration.instance_eval do 68: begin 69: undef_method(k) 70: rescue NameError => e 71: end 72: end 73: end 74: end 75: end
Does a hard reset of the Configatron::Configuration class. All methods are undefined, the list of configuration parameters is emptied, and the nil_for_missing method gets reset to false.
# File lib/configatron/configuration.rb, line 57 57: def reset! 58: reset 59: self.nil_for_missing = false 60: @_storage_list = [] 61: end