Module: Bookends::Config
Instance Attribute Summary collapse
-
#_config ⇒ Object
readonly
Returns the value of attribute _config.
Instance Method Summary collapse
-
#deep_merge!(target, data) ⇒ Object
deep_merge by Stefan Rusterholz, see www.ruby-forum.com/topic/142809.
- #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
20 21 22 |
# File 'lib/bookends/config.rb', line 20 def method_missing(name, *args, &block) @_config[name.to_sym] || fail(NoMethodError, "Calling undefined Bookends config: #{name}", caller) end |
Instance Attribute Details
#_config ⇒ Object (readonly)
Returns the value of attribute _config.
6 7 8 |
# File 'lib/bookends/config.rb', line 6 def _config @_config end |
Instance Method Details
#deep_merge!(target, data) ⇒ Object
deep_merge by Stefan Rusterholz, see www.ruby-forum.com/topic/142809
15 16 17 18 |
# File 'lib/bookends/config.rb', line 15 def deep_merge!(target, data) merger = proc{ |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 } target.merge! data, &merger end |
#load!(filename, options = {}) ⇒ Object
8 9 10 11 12 |
# File 'lib/bookends/config.rb', line 8 def load!(filename, = {}) configs = Psych.safe_load(File.read(filename), aliases: true).deep_symbolize_keys configs = configs[[:env].to_sym] if [:env] && configs[[:env].to_sym] deep_merge!(@_config, configs) end |