Class | Loquacious::Configuration::Iterator |
In: |
lib/loquacious/configuration/iterator.rb
|
Parent: | Object |
Provides an external iteraotr for a Loquacious::Configuration object. The iterator allows the user to retrieve all the configuration settings along with their descriptions and values.
cfg = Configuration.for('foo') { bar 'value', :desc => 'the bar attribute' baz 42, :desc => 'the baz attribute' } i = Iterator.new(cfg) i.each do |node| puts "#{node.name} :: #{node.desc}" end
Results in
bar :: the bar attribute baz :: the baz attribute
Frame | = | Struct.new( :config, :prefix, :keys, :index ) | Structure describing a single iteration stack frame. A new stack frame is created when we descend into a nested Configuration object. | |
Node | = | Struct.new( :config, :name, :desc, :key ) { def obj() config.__send__(key); | This is a single node in a Configuration object. It corresponds to a single configuration attribute. |
Create a new iterator that will operate on the config (configuration object). The iterator allows the attributes of the configuration object to be accessed — this includes nested configuration objects.
Iterate over each node in the configuration object yielding each to the supplied block in turn. The return value of the block is returned from this method. nil is returned if there are no nodes in the iterator.
If an attribute is given, then the iteration starts at that particular attribute and recurse if it is a nested configuration. Otherwise, only that attribute is yielded to the block.