Module: Mongoid::Config::Options
- Included in:
- Mongoid::Config
- Defined in:
- lib/mongoid/config/options.rb
Overview
Encapsulates logic for setting options.
Instance Method Summary collapse
-
#defaults ⇒ Hash
Get the defaults or initialize a new empty hash.
-
#log_level ⇒ Integer
Get the log level.
-
#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.
15 16 17 |
# File 'lib/mongoid/config/options.rb', line 15 def defaults @defaults ||= {} end |
#log_level ⇒ Integer
Get the log level.
78 79 80 81 82 83 84 85 86 |
# File 'lib/mongoid/config/options.rb', line 78 def log_level if level = settings[:log_level] unless level.is_a?(Integer) level = level.upcase.to_s level = "Logger::#{level}".constantize end level end end |
#option(name, options = {}) ⇒ Object
Define a configuration option with a default.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/mongoid/config/options.rb', line 30 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.
58 59 60 |
# File 'lib/mongoid/config/options.rb', line 58 def reset settings.replace(defaults) end |
#settings ⇒ Hash
Get the settings or initialize a new empty hash.
68 69 70 |
# File 'lib/mongoid/config/options.rb', line 68 def settings @settings ||= {} end |