Class: Cottontail::Configurable::Configuration
- Inherits:
-
Object
- Object
- Cottontail::Configurable::Configuration
- Defined in:
- lib/cottontail/configurable.rb
Overview
:nodoc:
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#get(key) ⇒ Object
Get a configuration option.
- #inheritable_copy ⇒ Object
-
#initialize(parent = nil) ⇒ Configuration
constructor
A new instance of Configuration.
- #reset! ⇒ Object
-
#set(key, value = nil, &block) ⇒ Object
Set a configuration option.
Constructor Details
#initialize(parent = nil) ⇒ Configuration
Returns a new instance of Configuration.
35 36 37 38 39 40 41 |
# File 'lib/cottontail/configurable.rb', line 35 def initialize(parent = nil) reset! if parent.kind_of?(Cottontail::Configuration) parent.each { |k, v| set(k, v) } end end |
Instance Method Details
#each(&block) ⇒ Object
66 67 68 |
# File 'lib/cottontail/configurable.rb', line 66 def each(&block) @settings.each(&block) end |
#get(key) ⇒ Object
Get a configuration option. It will be evalued of the first time of calling.
57 58 59 60 61 62 63 |
# File 'lib/cottontail/configurable.rb', line 57 def get(key) if (value = @settings[key]).is_a?(Proc) @settings[key] = value.call end @settings[key] end |
#inheritable_copy ⇒ Object
71 72 73 |
# File 'lib/cottontail/configurable.rb', line 71 def inheritable_copy self.class.new(self) end |
#reset! ⇒ Object
76 77 78 |
# File 'lib/cottontail/configurable.rb', line 76 def reset! @settings = {} end |
#set(key, value = nil, &block) ⇒ Object
Set a configuration option.
48 49 50 |
# File 'lib/cottontail/configurable.rb', line 48 def set(key, value = nil, &block) @settings[key] = block.nil? ? value : block end |