Class: Bozo::Configuration::ConfigurationGroup
- Inherits:
-
Object
- Object
- Bozo::Configuration::ConfigurationGroup
- Defined in:
- lib/bozo/configuration.rb
Overview
Class for controlling the creation and retrieval of configuration groups and values.
Should not be used outside of this class.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Returns the configuration value for the key.
-
#apply(block) ⇒ Object
Yields the internal binding of the configuration group to the given block.
-
#ensure_child(key) ⇒ Object
Ensures the hash contains a child hash for the specified key and returns it.
-
#initialize(*parents) ⇒ ConfigurationGroup
constructor
Create a new instance.
-
#inspect ⇒ Object
Return the current state of the configuration.
-
#method_missing(sym, *args, &block) ⇒ Object
Enables the fluent retrieval of groups within the hash.
-
#set_value(key, value) ⇒ Object
Sets the value of the specified key.
Constructor Details
#initialize(*parents) ⇒ ConfigurationGroup
Create a new instance.
88 89 90 91 |
# File 'lib/bozo/configuration.rb', line 88 def initialize(*parents) @parents = parents @hash = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
Enables the fluent retrieval of groups within the hash.
94 95 96 97 |
# File 'lib/bozo/configuration.rb', line 94 def method_missing(sym, *args, &block) raise missing_child sym unless @hash.key? sym @hash[sym] end |
Instance Method Details
#[](key) ⇒ Object
Returns the configuration value for the key
102 103 104 |
# File 'lib/bozo/configuration.rb', line 102 def [](key) @hash[key] end |
#apply(block) ⇒ Object
Yields the internal binding of the configuration group to the given block.
131 132 133 |
# File 'lib/bozo/configuration.rb', line 131 def apply(block) block.call(binding) end |
#ensure_child(key) ⇒ Object
Ensures the hash contains a child hash for the specified key and returns it.
111 112 113 114 |
# File 'lib/bozo/configuration.rb', line 111 def ensure_child(key) @hash[key] = ConfigurationGroup.new(@parents + [key]) unless @hash.key? key @hash[key] end |
#inspect ⇒ Object
Return the current state of the configuration.
136 137 138 |
# File 'lib/bozo/configuration.rb', line 136 def inspect @hash.inspect end |
#set_value(key, value) ⇒ Object
Sets the value of the specified key.
122 123 124 |
# File 'lib/bozo/configuration.rb', line 122 def set_value(key, value) @hash[key] = value end |