Module: Mongoid::Config::Options
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Extended In:
| |
Defined in: | lib/mongoid/config/options.rb |
Overview
Encapsulates logic for setting options.
Instance Method Summary
-
#defaults ⇒ Hash
Get the defaults or initialize a new empty hash.
-
#log_level ⇒ Integer
Get the log level.
-
#option(name, options = {})
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.
# File 'lib/mongoid/config/options.rb', line 16
def defaults @defaults ||= {} end
#log_level ⇒ Integer
Get the log level.
#option(name, options = {})
Define a configuration option with a default.
# File 'lib/mongoid/config/options.rb', line 31
def option(name, = {}) defaults[name] = settings[name] = [:default] class_eval do # log_level accessor is defined specially below unless name.to_sym == :log_level define_method(name) do settings[name] end end define_method("#{name}=") do |value| settings[name] = value [:on_change]&.call(value) end define_method("#{name}?") do !!send(name) end end end
#reset ⇒ Hash
Reset the configuration options to the defaults.
# File 'lib/mongoid/config/options.rb', line 59
def reset # do this via the setter for each option, so that any defined on_change # handlers can be invoked. defaults.each do |setting, default| send(:"#{setting}=", default) end end
#settings ⇒ Hash
Get the settings or initialize a new empty hash.
# File 'lib/mongoid/config/options.rb', line 73
def settings @settings ||= {} end