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
114 115 116 117 118 119 120 |
# File 'lib/locomotive/configuration.rb', line 114 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
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/locomotive/configuration.rb', line 100 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
94 95 96 |
# File 'lib/locomotive/configuration.rb', line 94 def default(key=nil) include?(key) ? self[key] : self[key] = self.class.new end |