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.
18 19 20 |
# File 'lib/mongoid/config/options.rb', line 18 def defaults @defaults ||= {} end |
#log_level ⇒ Integer
Get the log level.
86 87 88 89 90 91 92 93 94 |
# File 'lib/mongoid/config/options.rb', line 86 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.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mongoid/config/options.rb', line 33 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 end define_method("#{name}?") do !!send(name) end end end |
#reset ⇒ Hash
Reset the configuration options to the defaults.
62 63 64 |
# File 'lib/mongoid/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/mongoid/config/options.rb', line 74 def settings @settings ||= {} end |