Module: Mongoid::Config
- Includes:
- ActiveModel::Observing
- Included in:
- Config
- Defined in:
- lib/mongoid/config.rb,
lib/mongoid/config/options.rb,
lib/mongoid/config/database.rb,
lib/mongoid/config/environment.rb,
lib/mongoid/config/replset_database.rb
Overview
:nodoc:
Defined Under Namespace
Modules: Environment, Options Classes: Database, ReplsetDatabase
Constant Summary collapse
- PRIVATE_OPTIONS =
keys to remove from self to not pass through to Mongo::Connection
%w(uri host hosts port database databases username password logger use_activesupport_time_zone)
Instance Attribute Summary collapse
-
#master ⇒ Mongo::DB
(also: #database)
Returns the master database, or if none has been set it will raise an error.
- #master The master database.(Themasterdatabase.) ⇒ Object
-
#use_activesupport_time_zone ⇒ Object
(also: #use_activesupport_time_zone?)
Returns the value of attribute use_activesupport_time_zone.
Instance Method Summary collapse
-
#add_language(language_code = nil) ⇒ Object
Adds a new I18n locale file to the load path.
-
#blacklisted_options ⇒ Array<String>
Get the blacklisted options from passing through to the driver.
-
#databases ⇒ Hash
Get any extra databases that have been configured.
-
#databases=(databases) ⇒ Object
what the exact expectation was.
-
#default_logger ⇒ Logger
Returns the default logger, which is either a Rails logger of stdout logger.
-
#destructive_fields ⇒ Array<String>
Return field names that could cause destructive things to happen if defined in a Mongoid::Document.
-
#from_hash(options = {}) ⇒ Object
Configure mongoid from a hash.
-
#load!(path) ⇒ Object
Load the settings from a compliant mongoid.yml file.
-
#logger ⇒ Logger
Returns the logger, or defaults to Rails logger or stdout logger.
-
#logger=(logger) ⇒ Logger
Sets the logger for Mongoid to use.
-
#purge! ⇒ Object
Purge all data in all collections, including indexes.
-
#reconnect!(now = true) ⇒ Object
Convenience method for connecting to the master database after forking a new process.
Methods included from Options
defaults, option, reset, settings
Instance Attribute Details
#master ⇒ Mongo::DB Also known as: database
Returns the master database, or if none has been set it will raise an error.
20 21 22 |
# File 'lib/mongoid/config.rb', line 20 def master @master end |
#master The master database.(Themasterdatabase.) ⇒ Object
20 |
# File 'lib/mongoid/config.rb', line 20 attr_accessor :master |
#use_activesupport_time_zone ⇒ Object Also known as: use_activesupport_time_zone?
Returns the value of attribute use_activesupport_time_zone.
192 193 194 |
# File 'lib/mongoid/config.rb', line 192 def use_activesupport_time_zone @use_activesupport_time_zone end |
Instance Method Details
#add_language(language_code = nil) ⇒ Object
Adds a new I18n locale file to the load path.
46 47 48 49 50 51 52 53 54 |
# File 'lib/mongoid/config.rb', line 46 def add_language(language_code = nil) Dir[ File.join( File.dirname(__FILE__), "..", "config", "locales", "#{language_code}.yml" ) ].each do |file| I18n.load_path << File.(file) end end |
#blacklisted_options ⇒ Array<String>
Get the blacklisted options from passing through to the driver.
69 70 71 |
# File 'lib/mongoid/config.rb', line 69 def PRIVATE_OPTIONS + settings.keys.map(&:to_s) end |
#databases ⇒ Hash
Get any extra databases that have been configured.
79 80 81 82 |
# File 'lib/mongoid/config.rb', line 79 def databases configure_extras(@settings["databases"]) unless @databases || !@settings @databases || {} end |
#databases=(databases) ⇒ Object
Durran: There were no tests around the databases setter, not sure
what the exact expectation was. Set with a hash?
86 87 |
# File 'lib/mongoid/config.rb', line 86 def databases=(databases) end |
#default_logger ⇒ Logger
Returns the default logger, which is either a Rails logger of stdout logger
136 137 138 |
# File 'lib/mongoid/config.rb', line 136 def default_logger defined?(Rails) && Rails.respond_to?(:logger) ? Rails.logger : ::Logger.new($stdout) end |
#destructive_fields ⇒ Array<String>
Return field names that could cause destructive things to happen if defined in a Mongoid::Document.
96 97 98 |
# File 'lib/mongoid/config.rb', line 96 def destructive_fields Components.prohibited_methods end |
#from_hash(options = {}) ⇒ Object
Configure mongoid from a hash. This is usually called after parsing a yaml config file such as mongoid.yml.
107 108 109 110 111 112 113 |
# File 'lib/mongoid/config.rb', line 107 def from_hash( = {}) .except("database", "slaves", "databases").each_pair do |name, value| send("#{name}=", value) if respond_to?("#{name}=") end @master, @slaves = configure_databases() configure_extras(["databases"]) end |
#load!(path) ⇒ Object
Load the settings from a compliant mongoid.yml file. This can be used for easy setup with frameworks other than Rails.
124 125 126 127 128 |
# File 'lib/mongoid/config.rb', line 124 def load!(path) Environment.load_yaml(path).tap do |settings| from_hash(settings) if settings.present? end end |
#logger ⇒ Logger
Returns the logger, or defaults to Rails logger or stdout logger.
146 147 148 149 |
# File 'lib/mongoid/config.rb', line 146 def logger @logger = default_logger unless defined?(@logger) @logger end |
#logger=(logger) ⇒ Logger
Sets the logger for Mongoid to use.
157 158 159 160 161 162 163 164 |
# File 'lib/mongoid/config.rb', line 157 def logger=(logger) case logger when false, nil then @logger = nil when true then @logger = default_logger else @logger = logger if logger.respond_to?(:info) end end |
#purge! ⇒ Object
Purge all data in all collections, including indexes.
172 173 174 175 176 |
# File 'lib/mongoid/config.rb', line 172 def purge! master.collections.map do |collection| collection.drop if collection.name !~ /system/ end end |
#reconnect!(now = true) ⇒ Object
Convenience method for connecting to the master database after forking a new process.
241 242 243 244 245 246 247 248 249 |
# File 'lib/mongoid/config.rb', line 241 def reconnect!(now = true) if now master.connection.connect else # We set a @reconnect flag so that #master knows to reconnect the next # time the connection is accessed. @reconnect = true end end |