Class: Bozo::Configuration::ConfigurationGroup

Inherits:
Object
  • Object
show all
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

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

Parameters:

  • key (Symbol)


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.

Parameters:

  • block (Proc)

    The block to yield the internal binding to.



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.

Parameters:

  • key (Symbol)

    The key that must contain a child hash.



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

#inspectObject

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.

Parameters:

  • key (Symbol)

    The key to set the value of.

  • value (Object)

    The value to set for the specified key.



122
123
124
# File 'lib/bozo/configuration.rb', line 122

def set_value(key, value)
  @hash[key] = value
end