Module: Upman::Core::Config
Instance Attribute Summary collapse
-
#_config ⇒ Object
readonly
Returns the value of attribute _config.
Instance Method Summary collapse
-
#deep_merge!(target, data) ⇒ Object
Deep merging of hashes deep_merge by Stefan Rusterholz, see www.ruby-forum.com/topic/142809.
- #get!(key) ⇒ Object
- #load!(filename, options = {}) ⇒ Object
- #method_missing(name, *args, &block) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
28 29 30 31 |
# File 'lib/upman/core/config.rb', line 28 def method_missing(name, *args, &block) @_config[name.to_sym] || fail(NoMethodError, "unknown configuration root #{name}", caller) end |
Instance Attribute Details
#_config ⇒ Object (readonly)
Returns the value of attribute _config.
8 9 10 |
# File 'lib/upman/core/config.rb', line 8 def _config @_config end |
Instance Method Details
#deep_merge!(target, data) ⇒ Object
Deep merging of hashes deep_merge by Stefan Rusterholz, see www.ruby-forum.com/topic/142809
22 23 24 25 26 |
# File 'lib/upman/core/config.rb', line 22 def deep_merge!(target, data) merger = proc {|key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2} target.merge! data, &merger end |
#get!(key) ⇒ Object
16 17 18 |
# File 'lib/upman/core/config.rb', line 16 def get!(key) return @_config[key] end |
#load!(filename, options = {}) ⇒ Object
10 11 12 13 14 |
# File 'lib/upman/core/config.rb', line 10 def load!(filename, = {}) newsets = YAML::load_file(filename).deep_symbolize_keys newsets = newsets[[:env].to_sym] if [:env] && newsets[[:env].to_sym] deep_merge!(@_config, newsets) end |