Module: Dynamoid::Config::Options
- Included in:
- Dynamoid::Config
- Defined in:
- lib/dynamoid/config/options.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.
17 18 19 |
# File 'lib/dynamoid/config/options.rb', line 17 def defaults @defaults ||= {} end |
#option(name, options = {}) ⇒ Object
Define a configuration option with a default.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dynamoid/config/options.rb', line 32 def option(name, = {}) defaults[name] = settings[name] = [:default] class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{name} # def endpoint settings[#{name.inspect}] # settings["endpoint"] end # end def #{name}=(value) # def endpoint=(value) settings[#{name.inspect}] = value # settings["endpoint"] = value end # end def #{name}? # def endpoint? #{name} # endpoint end # end def reset_#{name} # def reset_endpoint settings[#{name.inspect}] = defaults[#{name.inspect}] # settings["endpoint"] = defaults["endpoint"] end # end RUBY end |
#reset ⇒ Hash
Reset the configuration options to the defaults.
62 63 64 |
# File 'lib/dynamoid/config/options.rb', line 62 def reset settings.replace(defaults) end |
#settings ⇒ Hash
Get the settings or initialize a new empty hash.
74 75 76 |
# File 'lib/dynamoid/config/options.rb', line 74 def settings @settings ||= {} end |