Object
Implementation of a domain specific language for creating configuration objects. Blocks of code are evaluted by the DSL which returns a new configuration object.
Creates a new DSL and evaluates the given block in the context of the DSL.
# File lib/loquacious/configuration.rb, line 314 def initialize( opts = {}, &block ) @description = nil @__config = opts[:config] || Configuration.new @__config.__defaults_mode = opts.key?(:defaults_mode) ? opts[:defaults_mode] : false instance_eval(&block) ensure @__config.__defaults_mode = false end
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 346 def desc( string ) string = string.to_s string.strip! string.gutter! @description = string.empty? ? nil : string end
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 328 def method_missing( method, *args, &block ) m = method.to_s.delete('=').to_sym if args.length > 1 opts = args.last.instance_of?(Hash) ? args.pop : {} self.desc(opts[:desc]) if opts.has_key? :desc end rv = __config.__send(m, *args, &block) __config.__desc[m] = @description if @description @description = nil rv end
Generated with the Darkfish Rdoc Generator 2.