Class: Locomotive::ConfigurationHash
- Defined in:
- lib/locomotive/configuration.rb
Overview
specialized hash for storing configuration settings
Instance Method Summary collapse
-
#[](key, &block) ⇒ Object
retrieves the specified key and yields it if a block is provided.
-
#default(key = nil) ⇒ Object
ensure that default entries always produce instances of the ConfigurationHash class.
-
#method_missing(name, *args, &block) ⇒ Object
provides member-based access to keys i.e.
Methods inherited from Hash
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
provides member-based access to keys i.e. params.id === params note: all keys are converted to symbols
122 123 124 125 126 127 128 |
# File 'lib/locomotive/configuration.rb', line 122 def method_missing(name, *args, &block) if name.to_s.ends_with? '=' send :[]=, name.to_s.chomp('=').to_sym, *args else send(:[], name.to_sym, &block) end end |
Instance Method Details
#[](key, &block) ⇒ Object
retrieves the specified key and yields it if a block is provided
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/locomotive/configuration.rb', line 108 def [](key, &block) if block_given? self.delete(key) unless super(key).respond_to?(:keys) yield(super(key)) else super(key) end # block_given? ? yield(super(key)) : super(key) end |
#default(key = nil) ⇒ Object
ensure that default entries always produce instances of the ConfigurationHash class
102 103 104 |
# File 'lib/locomotive/configuration.rb', line 102 def default(key=nil) include?(key) ? self[key] : self[key] = self.class.new end |