Module: Mongoid::Config
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
self,
DeprecatedOptions
|
|
Defined in: | lib/mongoid/config.rb, lib/mongoid/config/defaults.rb, lib/mongoid/config/encryption.rb, lib/mongoid/config/environment.rb, lib/mongoid/config/introspection.rb, lib/mongoid/config/options.rb, lib/mongoid/config/validators/async_query_executor.rb, lib/mongoid/config/validators/client.rb, lib/mongoid/config/validators/option.rb |
Overview
This module defines all the configuration options for ::Mongoid
, including the database connections.
Constant Summary
Class Method Summary
Encryption
- Extended
encryption_schema_map | Generate the encryption schema map for the provided models. |
algorithm_for | Get the encryption algorithm to use for the provided field. |
bson_type_for | Get the |
key_id_for | Get the keyId encryption schema field for the base64 encrypted key id. |
metadata_for | Generate the encryptMetadata object for the provided model. |
properties_for | Generate encryption properties for the provided model. |
properties_for_fields | Generate encryption properties for the fields of the provided model. |
properties_for_relations | Generate encryption properties for the relations of the provided model. |
Defaults
- Extended
load_defaults | Load the defaults for the feature flags in the given |
Options
- Extended
Instance Attribute Summary
-
#clients ⇒ Hash
rw
Get the client configuration or an empty hash.
-
#configured? ⇒ true | false
readonly
Has Mongoid been configured? This is checking that at least a valid client config exists.
-
#options=(options)
writeonly
::Set
the configuration options. - #running_with_passenger? ⇒ true | false readonly deprecated Deprecated.
- #clients=(clients) rw private
Instance Method Summary
-
#config ⇒ self
Returns the
Config
singleton, for use in the configure DSL. -
#connect_to(name, options = { read: { mode: :primary }})
Connect to the provided database name on the default client.
-
#deregister_model(klass)
Internal use only
Internal use only
Deregister a model in the application with
::Mongoid
. -
#destructive_fields ⇒ Array<String>
Return field names that could cause destructive things to happen if defined in a
Document
. -
#load!(path, environment = nil)
Load the settings from a compliant mongoid.yml file.
-
#load_configuration(settings)
From a hash of settings, load all the configuration.
-
#models ⇒ Array<Class>
Get all the models in the application - this is everything that includes
Document
. -
#override_client(name) ⇒ String | Symbol
Override the client to use globally.
-
#override_database(name) ⇒ String | Symbol
Override the database to use globally.
-
#purge! ⇒ true
Purge all data in all collections, including indexes.
-
#register_model(klass)
Register a model in the application with
::Mongoid
. -
#time_zone ⇒ String
Get the time zone to use.
-
#truncate! ⇒ true
Truncate all data in all collections, but not the indexes.
-
#global_client ⇒ Mongo::Client
private
Get database client that respects global overrides
Config
.override_database andConfig
.override_client. - #set_log_levels private
Instance Attribute Details
#clients ⇒ Hash (rw)
Get the client configuration or an empty hash.
# File 'lib/mongoid/config.rb', line 368
def clients @clients ||= {} end
#clients=(clients) (rw, private)
# File 'lib/mongoid/config.rb', line 403
def clients=(clients) raise Errors::NoClientsConfig.new unless clients c = clients.with_indifferent_access Validators::Client.validate(c) @clients = c end
#configured? ⇒ true
| false
(readonly)
Has Mongoid been configured? This is checking that at least a valid client config exists.
# File 'lib/mongoid/config.rb', line 197
def configured? clients.key?(:default) end
#options=(options) (writeonly)
::Set
the configuration options. Will validate each one individually.
# File 'lib/mongoid/config.rb', line 352
def ( ) if Validators::AsyncQueryExecutor.validate( ) .each_pair do |option, value| Validators::Option.validate(option) send("#{option}=", value) end end end
#running_with_passenger? ⇒ true
| false
(readonly)
Is the application running under passenger?
# File 'lib/mongoid/config.rb', line 390
def running_with_passenger? @running_with_passenger ||= defined?(PhusionPassenger) end
Instance Method Details
#config ⇒ self
Returns the Config
singleton, for use in the configure DSL.
# File 'lib/mongoid/config.rb', line 186
def config self end
#connect_to(name, options = { read: { mode: :primary }})
Use only in development or test environments for convenience.
Connect to the provided database name on the default client.
# File 'lib/mongoid/config.rb', line 209
def connect_to(name, = { read: { mode: :primary }}) self.clients = { default: { database: name, hosts: [ "localhost:27017" ], options: } } end
#deregister_model(klass)
Deregister a model in the application with ::Mongoid
.
#destructive_fields ⇒ Array<String>
Return field names that could cause destructive things to happen if defined in a Document
.
# File 'lib/mongoid/config.rb', line 226
def destructive_fields Composable.prohibited_methods end
#global_client ⇒ Mongo::Client
(private)
Get database client that respects global overrides Config
.override_database and Config
.override_client.
# File 'lib/mongoid/config.rb', line 414
def global_client client = if Threaded.client_override Clients.with_name(Threaded.client_override) else Clients.default end if Threaded.database_override client.use(Threaded.database_override) else client end end
#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
.
# File 'lib/mongoid/config.rb', line 238
def load!(path, environment = nil) settings = Environment.load_yaml(path, environment) if settings.present? Clients.disconnect Clients.clear load_configuration(settings) end settings end
#load_configuration(settings)
From a hash of settings, load all the configuration.
# File 'lib/mongoid/config.rb', line 288
def load_configuration(settings) configuration = settings.with_indifferent_access self. = configuration[: ] self.clients = configuration[:clients] Mongo. = configuration[: ] || {} set_log_levels end
#models ⇒ Array<Class
>
Get all the models in the application - this is everything that includes Document
.
# File 'lib/mongoid/config.rb', line 255
def models @models ||= [] end
#override_client(name) ⇒ String | Symbol
Override the client to use globally.
# File 'lib/mongoid/config.rb', line 316
def override_client(name) Threaded.client_override = name ? name.to_s : nil end
#override_database(name) ⇒ String | Symbol
Override the database to use globally.
# File 'lib/mongoid/config.rb', line 304
def override_database(name) Threaded.database_override = name end
#purge! ⇒ true
This is the fastest way to drop all data.
Purge all data in all collections, including indexes.
# File 'lib/mongoid/config.rb', line 328
def purge! global_client.database.collections.each(&:drop) and true end
#register_model(klass)
Register a model in the application with ::Mongoid
.
#set_log_levels (private)
[ GitHub ]#time_zone ⇒ String
Get the time zone to use.
# File 'lib/mongoid/config.rb', line 378
def time_zone use_utc? ? "UTC" : ::Time.zone end
#truncate! ⇒ true
This will be slower than purge!
Truncate all data in all collections, but not the indexes.
# File 'lib/mongoid/config.rb', line 340
def truncate! global_client.database.collections.each do |collection| collection.find.delete_many end and true end