Module: Sandrbox::Config::Options
- Included in:
- Sandrbox::Config
- Defined in:
- lib/sandrbox/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/sandrbox/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/sandrbox/options/option.rb', line 27 def option(name, = {}) defaults[name] = settings[name] = [:default] class_eval <<-RUBY def #{name} settings[#{name.inspect}] end def #{name}=(value) settings[#{name.inspect}] = value end def #{name}? #{name} end def reset_#{name} settings[#{name.inspect}] = defaults[#{name.inspect}] end RUBY end |
#reset ⇒ Hash
Reset the configuration options to the defaults.
55 56 57 |
# File 'lib/sandrbox/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/sandrbox/options/option.rb', line 65 def settings @settings ||= {} end |