module Twigg::Settings::DSL::ClassMethods

Attributes

overrides[R]

Private Instance Methods

namespace(scope) { || ... } click to toggle source

DSL method for declaring settings underneath a namespace.

Example:

namespace :app do
  setting :bind, default: '0.0.0.0'
end
# File lib/twigg/settings/dsl.rb, line 27
def namespace(scope, &block)
  namespaces.push scope
  yield
ensure
  namespaces.pop
end
namespaces() click to toggle source
# File lib/twigg/settings/dsl.rb, line 15
def namespaces
  @namespaces ||= []
end
setting(name, options = {}, &block) click to toggle source

DSL method which is used to create a reader for the setting `name`. If the configuration file does not contain a value for the setting, return `options` from the `options` hash.

A block maybe provided to do checking of the supplied value prior to returning; for an example, see the `repositories_directory` setting in this file.

Note that this method doesn't actually create any readers; it merely records data about default values and validation which are then used at initialization time to override the readers provided by OpenStruct itself.

# File lib/twigg/settings/dsl.rb, line 46
def setting(name, options = {}, &block)
  options.merge!(block: block)
  @overrides ||= {}

  overrides = namespaces.inject(@overrides) do |overrides, namespace|
    overrides[namespace] ||= Namespace.new
  end

  overrides[name] = options
end