Module: Cloudsearchable::Config::Options::ClassMethods
- Defined in:
- lib/cloudsearchable/config/options.rb
Instance Method Summary collapse
-
#defaults ⇒ Object
Get the defaults or initialize a new empty hash.
-
#option(name, options = {}) ⇒ Object
Define a configuration option with a default.
-
#reset ⇒ Object
Reset the configuration options to the defaults.
-
#settings ⇒ Object
Get the settings or initialize a new empty hash.
Instance Method Details
#defaults ⇒ Object
Get the defaults or initialize a new empty hash.
12 13 14 |
# File 'lib/cloudsearchable/config/options.rb', line 12 def defaults @defaults ||= {} end |
#option(name, options = {}) ⇒ Object
Define a configuration option with a default. Example usage:
Options.option(:persist_in_safe_mode, :default => false)
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cloudsearchable/config/options.rb', line 28 def option(name, = {}) defaults[name] = settings[name] = [:default] define_method name do settings[name] end define_method "#{name}=" do |value| settings[name] = value end define_method "#{name}?" do !!settings[name] end define_method "reset_#{name}" do settings[name] = defaults[name] end end |
#reset ⇒ Object
Reset the configuration options to the defaults.
17 18 19 |
# File 'lib/cloudsearchable/config/options.rb', line 17 def reset settings.replace(defaults) end |
#settings ⇒ Object
Get the settings or initialize a new empty hash.
22 23 24 |
# File 'lib/cloudsearchable/config/options.rb', line 22 def settings @settings ||= {} end |