Module: ConfigSL::DSL

Included in:
Config
Defined in:
lib/configsl/dsl.rb

Overview

DSL (Domain Specific Language) for defining configuration options.

This module provides the base functionality for building configuration classes. It should be included before any other modules that provide additional functionality, such as formatting or validation.

The class that includes this module will need to set the values for the options before they can be used. The easiest way to do this is to call ‘set_value` with each option and its value in the constructor.

Examples:

def initialize(params = {})
  params.each do |name, value|
    set_value(name, value)
  end
end

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Include the class methods when the module is included.



24
25
26
# File 'lib/configsl/dsl.rb', line 24

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#optionsHash

Returns the options hash for the class of the current instance.

Returns:

  • (Hash)

    The options hash.



31
32
33
# File 'lib/configsl/dsl.rb', line 31

def options
  self.class.options
end

#valuesArray<Hash>

Returns the values of all the options.

Returns:

  • (Array<Hash>)

    The values of all the options.



38
39
40
# File 'lib/configsl/dsl.rb', line 38

def values
  options.each_key.to_h { |name| [name, get_value(name)] }
end