Parent

Loquacious::Configuration::DSL

Implementation of a doman specific language for creating configuration objects. Blocks of code are evaluted by the DSL which returns a new configuration object.

Attributes

__config[R]

Returns the configuration object.

Public Class Methods

evaluate( &block ) click to toggle source

Create a new DSL and evaluate the given block in the context of the DSL. Returns a newly created configuration object.

     # File lib/loquacious/configuration.rb, line 207
207:       def self.evaluate( &block )
208:         dsl = self.new(&block)
209:         dsl.__config
210:       end
new( config = nil, &block ) click to toggle source

Creates a new DSL and evaluates the given block in the context of the DSL.

     # File lib/loquacious/configuration.rb, line 218
218:       def initialize( config = nil, &block )
219:         @description = nil
220:         @__config = config || Configuration.new
221:         __instance_eval(&block)
222:       end

Public Instance Methods

desc( string ) click to toggle source

Store the string as the description for the next attribute that will be configured. This description will be overwritten if the attribute has a description passed as an options hash.

     # File lib/loquacious/configuration.rb, line 247
247:       def desc( string )
248:         string = string.to_s
249:         string.strip!
250:         string.gutter!
251:         @description = string.empty? ? nil : string
252:       end
method_missing( method, *args, &block ) click to toggle source

Dynamically adds the given method to the configuration as an attribute. The args will be used to set the value of the attribute. If a block is given then the args are ignored and the attribute will be a nested configuration object.

     # File lib/loquacious/configuration.rb, line 229
229:       def method_missing( method, *args, &block )
230:         m = method.to_s.delete('=').to_sym
231: 
232:         if args.length > 1
233:           opts = args.last.instance_of?(Hash) ? args.pop : {}
234:           self.desc(opts[:desc]) if opts.has_key? :desc
235:         end
236: 
237:         rv = __config.__send(m, *args, &block)
238:         __config.__desc[m] = @description if @description
239:         @description = nil
240:         rv
241:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.