Parent

Loquacious::Configuration

Constants

Keepers

Attributes

__desc[R]

Accessor for the description hash.

Public Class Methods

for( name ) { block } click to toggle source

Returns the configuration associated with the given name. If a block is given, then it will be used to create the configuration.

The same name can be used multiple times with different configuration blocks. Each different block will be used to add to the configuration; i.e. the configurations are additive.

    # File lib/loquacious/configuration.rb, line 25
25:       def for( name, &block )
26:         if block.nil?
27:           return @table.has_key?(name) ? @table[name] : nil
28:         end
29: 
30:         if @table.has_key? name
31:           DSL.new(@table[name], &block)
32:         else
33:           @table[name] = DSL.evaluate(&block)
34:         end
35:       end
help_for( name, opts = {} ) click to toggle source

Returns a Help instance for the configuration associated with the given name. See the Help#initialize method for the options that can be used with this method.

    # File lib/loquacious/configuration.rb, line 44
44:       def help_for( name, opts = {} )
45:         ::Loquacious::Configuration::Help.new(name, opts)
46:       end
new( &block ) click to toggle source

Create a new configuration object and initialize it using an optional block of code.

    # File lib/loquacious/configuration.rb, line 70
70:     def initialize( &block )
71:       @__desc = Hash.new
72:       self.merge!(DSL.evaluate(&block)) if block
73:     end

Public Instance Methods

[]( key ) click to toggle source

Provides hash accessor notation for configuration values.

  config = Configuration.for('app') {
             port  1234
           }
  config[:port]  #=> 1234
  config.port    #=> 1234
     # File lib/loquacious/configuration.rb, line 165
165:     def []( key )
166:       self.__send(key)
167:     end
[]=( key, value ) click to toggle source

Provides hash accessor notation for configuration values.

  config = Configuration.for('app')
  config[:port] = 8808
  config.port            #=> 8808
     # File lib/loquacious/configuration.rb, line 175
175:     def []=( key, value )
176:       self.__send(key, value)
177:     end
__eigenclass_eval( code ) click to toggle source

Evaluate the given code string in the context of this object’s eigenclass (singleton class).

     # File lib/loquacious/configuration.rb, line 126
126:     def __eigenclass_eval( code )
127:       ec = class << self; self; end
128:       ec.module_eval code
129:     rescue StandardError
130:       Kernel.raise Error, "cannot evalutate this code:\n#{code}\n"
131:     end
__send( symbol, *args, &block ) click to toggle source

Only invoke public methods on the Configuration instances.

     # File lib/loquacious/configuration.rb, line 115
115:     def __send( symbol, *args, &block )
116:       if self.respond_to? symbol
117:         self.__send__(symbol, *args, &block)
118:       else
119:         self.method_missing(symbol, *args, &block)
120:       end
121:     end
merge!( other ) click to toggle source

Merge the contents of the other configuration into this one. Values from the other configuratin will overwite values in this configuration.

This function is recursive. Nested configurations will be merged with their counterparts in the other configuration.

     # File lib/loquacious/configuration.rb, line 140
140:     def merge!( other )
141:       return self if other.equal? self
142:       Kernel.raise Error, "can only merge another Configuration" unless other.kind_of?(Configuration)
143: 
144:       other.__desc.each do |key,desc|
145:         value = other.__send(key)
146:         if self.__send(key).kind_of?(Configuration)
147:           self.__send(key).merge! value
148:         else
149:           self.__send("#{key}=", value)
150:         end
151:         __desc[key] = desc
152:       end
153: 
154:       self
155:     end
method_missing( method, *args, &block ) click to toggle source

When invoked, an attribute reader and writer are defined for the method. Any arguments given are used to set the value of the attributes. If a block is given, then the attribute is a nested configuration and the block is evaluated in the context of a new configuration object.

    # File lib/loquacious/configuration.rb, line 81
81:     def method_missing( method, *args, &block )
82:       m = method.to_s.delete('=').to_sym
83: 
84:       __eigenclass_eval "attr_writer :#{m}"
85:       __eigenclass_eval         def #{m}( *args, &block )          if args.empty? and !block            return @#{m} if @#{m}.kind_of?(Configuration)            return @#{m}.respond_to?(:call) ? @#{m}.call : @#{m}          end          v = (1 == args.length ? args.first : args)          v = DSL.evaluate(&block) if block          if @#{m}.kind_of?(Configuration)            @#{m}.merge! v          else            @#{m} = v          end          return @#{m} if @#{m}.kind_of?(Configuration)          return @#{m}.respond_to?(:call) ? @#{m}.call : @#{m}        end
86: 
87:       __desc[m] = nil unless __desc.has_key? m
88: 
89:       default = (args.empty? and !block) ? Loquacious::Undefined.new(m.to_s) : nil
90:       self.__send("#{m}=", default)
91:       self.__send("#{m}", *args, &block)
92:     end
obj() click to toggle source
     # File lib/loquacious/configuration/iterator.rb, line 148
148:       def obj()
149:         o = config.__send__(key)
150:         o.kind_of?(::Loquacious::Undefined) ? nil : o
151:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.