Class: Loquacious::Configuration::DSL

### Home Classes Methods

### In Files

- lib/loquacious/configuration.rb

### Parent

Object

### Methods

- ::evaluate
- ::new
- #desc
- #method_missing

### Files

- History.txt
- README.rdoc

### Class/Module Index

Quicksearch

- Loquacious
- Loquacious::Configuration
- Loquacious::Configuration::DSL
- Loquacious::Configuration::Help
- Loquacious::Configuration::Iterator
- Loquacious::Undefined
- String

No matching classes.

# Loquacious::Configuration::DSL

Implementation of a domain 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( opts = {}, &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 303
    def self.evaluate( opts = {}, &block )
      dsl = self.new(opts, &block)
      dsl.__config
    end

new( opts = {}, &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 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

### 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 346
    def desc( string )
      string = string.to_s
      string.strip!
      string.gutter!
      @description = string.empty? ? nil : string
    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 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.