Module: BuildBox::Config::Options
- Included in:
- BuildBox::Config
- Defined in:
- lib/build_box/options/option.rb
Overview
Encapsulates logic for setting options.
Instance Method Summary collapse
-
#defaults ⇒ Hash
Get the defaults or initialize a new empty hash.
-
#option(name, options = {}) ⇒ Object
Define a configuration option with a default.
-
#reset ⇒ Hash
Reset the configuration options to the defaults.
-
#settings ⇒ Hash
Get the settings or initialize a new empty hash.
Instance Method Details
#defaults ⇒ Hash
Get the defaults or initialize a new empty hash.
14 15 16 |
# File 'lib/build_box/options/option.rb', line 14 def defaults @defaults ||= {} end |
#option(name, options = {}) ⇒ Object
Define a configuration option with a default.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/build_box/options/option.rb', line 27 def option(name, = {}) defaults[name] = settings[name] = [:default] class_eval " def \#{name}\n settings[\#{name.inspect}]\n end\n\n def \#{name}=(value)\n settings[\#{name.inspect}] = value\n end\n\n def \#{name}?\n \#{name}\n end\n \n def reset_\#{name}\n settings[\#{name.inspect}] = defaults[\#{name.inspect}]\n end\n RUBY\nend\n" |
#reset ⇒ Hash
Reset the configuration options to the defaults.
55 56 57 |
# File 'lib/build_box/options/option.rb', line 55 def reset settings.replace(defaults) end |
#settings ⇒ Hash
Get the settings or initialize a new empty hash.
65 66 67 |
# File 'lib/build_box/options/option.rb', line 65 def settings @settings ||= {} end |