wpalmer / config-ruby-dsl

A DSL for defining and accessing configuration information

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DIW::Config

A ruby DSL for defining and accessing configuration data.

Main features:

  • method-style variable access
  • "sections" for grouping collections of variables
  • a "stack" onto which collections of variables can be pushed and popped
  • just-in-time calculations for any value responding to a call method

Example:

require 'diw/config'

cfg = ::DIW::Config::Config.new do
    section :aSection do
        var :aVariableName, "aVariableValue"
    end

    section :anotherSection do
        section :aSubSection do
            var :aVariableName, "anotherValue"
            var :aCalculatedValue, Proc.new { "a calculated value" }
        end
    end
end

puts cfg.anotherSection.aSubSection.aVariableName
# => anotherValue

puts cfg.anotherSection.aSubSection.aCalculatedValue
# => a calculated value

cfg.push do
    section :anotherSection
        section :aSubSection do
            var :aVariableName, "aStackOverride"
        end
    end
end

puts cfg.anotherSection.aSubSection.aVariableName
# => aStackOverride

About

A DSL for defining and accessing configuration information


Languages

Language:Ruby 100.0%