Module: Mongoid::Config
- Extended by:
- Config, Options
- Includes:
- ActiveModel::Observing
- Included in:
- Config
- Defined in:
- lib/mongoid/config.rb,
lib/mongoid/config/options.rb,
lib/mongoid/config/environment.rb,
lib/mongoid/config/validators/option.rb,
lib/mongoid/config/validators/session.rb
Overview
This module defines all the configuration options for Mongoid, including the database connections.
Defined Under Namespace
Modules: Environment, Options, Validators
Instance Method Summary (collapse)
-
- (Object) connect_to(name)
Connect to the provided database name on the default session.
-
- (Array<String>) destructive_fields
Return field names that could cause destructive things to happen if defined in a Mongoid::Document.
-
- (Object) load!(path, environment = nil)
Load the settings from a compliant mongoid.yml file.
-
- (Object) options=(options)
Set the configuration options.
-
- (true) purge!
Purge all data in all collections, including indexes.
-
- (Hash) sessions
Get the session configuration or an empty hash.
-
- (Object) sessions=(sessions)
Set the session configuration options.
-
- (String) time_zone
Get the time zone to use.
Methods included from Options
defaults, option, reset, settings
Instance Method Details
- (Object) connect_to(name)
Use only in development or test environments for convenience.
Connect to the provided database name on the default session.
65 66 67 68 69 70 71 72 |
# File 'lib/mongoid/config.rb', line 65 def connect_to(name) self.sessions = { default: { database: name, hosts: [ "localhost:27017" ] } } end |
- (Array<String>) destructive_fields
Return field names that could cause destructive things to happen if defined in a Mongoid::Document.
35 36 37 |
# File 'lib/mongoid/config.rb', line 35 def destructive_fields Components.prohibited_methods end |
- (Object) load!(path, environment = nil)
Load the settings from a compliant mongoid.yml file. This can be used for easy setup with frameworks other than Rails.
49 50 51 52 53 |
# File 'lib/mongoid/config.rb', line 49 def load!(path, environment = nil) settings = Environment.load_yaml(path, environment) load_configuration(settings) if settings.present? settings end |
- (Object) options=(options)
Set the configuration options. Will validate each one individually.
101 102 103 104 105 106 107 108 |
# File 'lib/mongoid/config.rb', line 101 def () if .each_pair do |option, value| Validators::Option.validate(option) send("#{option}=", value) end end end |
- (true) purge!
Durran: clean up.
Purge all data in all collections, including indexes.
84 85 86 87 88 89 90 91 |
# File 'lib/mongoid/config.rb', line 84 def purge! session = Sessions.default collections = session["system.namespaces"].find(name: { "$not" => /system|\$/ }).to_a collections.each do |collection| _, name = collection["name"].split(".", 2) session[name].drop end and true end |
- (Hash) sessions
Get the session configuration or an empty hash.
118 119 120 |
# File 'lib/mongoid/config.rb', line 118 def sessions @sessions ||= {} end |
- (Object) sessions=(sessions)
Set the session configuration options.
130 131 132 133 134 135 136 |
# File 'lib/mongoid/config.rb', line 130 def sessions=(sessions) raise Errors::NoSessionsConfig.new unless sessions sess = sessions.with_indifferent_access Validators::Session.validate(sess) @sessions = sess sess end |
- (String) time_zone
Get the time zone to use.
146 147 148 |
# File 'lib/mongoid/config.rb', line 146 def time_zone use_utc? ? "UTC" : ::Time.zone end |