module Mongoid::Config
def clients
-
(Hash)
- The clients configuration.
Other tags:
- Example: Get the clients configuration. -
def clients @clients ||= {} end
def clients=(clients)
def clients=(clients) raise Errors::NoClientsConfig.new unless clients c = clients.with_indifferent_access Validators::Client.validate(c) @clients = c end
def config
-
(self)
- The Config singleton.
def config self end
def configured?
-
(true | false)
- If Mongoid is configured.
Other tags:
- Example: Is Mongoid configured? -
def configured? clients.key?(:default) end
def connect_to(name, options = { read: { mode: :primary }})
-
name
(String
) -- The database name.
Other tags:
- Example: Set the database to connect to. -
Other tags:
- Note: - Use only in development or test environments for convenience.
def connect_to(name, options = { read: { mode: :primary }}) self.clients = { default: { database: name, hosts: [ "localhost:27017" ], options: options } } end
def deregister_model(klass)
- Api: - private
Parameters:
-
klass
(Class
) -- The model to deregister.
def deregister_model(klass) LOCK.synchronize do models.delete(klass) end end
def destructive_fields
-
(Array
- An array of bad field names.)
Other tags:
- Example: Get the destructive fields. -
def destructive_fields Composable.prohibited_methods end
def global_client
-
(Mongo::Client)
- Client according to global overrides.
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
def load!(path, environment = nil)
-
environment
(String | Symbol
) -- The environment to load. -
path
(String
) -- The path to the file.
Other tags:
- Example: Configure Mongoid. -
def load!(path, environment = nil) settings = Environment.load_yaml(path, environment) if settings.present? Clients.disconnect Clients.clear load_configuration(settings) end settings end
def load_configuration(settings)
-
settings
(Hash
) -- The configuration settings.
Other tags:
- Example: Load the configuration. -
def load_configuration(settings) configuration = settings.with_indifferent_access self.options = configuration[:options] self.clients = configuration[:clients] Mongo.options = configuration[:driver_options] || {} set_log_levels end
def models
-
(Array
- All the models in the application.)
Other tags:
- Example: Get all the models. -
def models @models ||= [] end
def options=(options)
-
options
(Hash
) -- The configuration options.
Other tags:
- Example: Set the options. -
def options=(options) if options Validators::AsyncQueryExecutor.validate(options) options.each_pair do |option, value| Validators::Option.validate(option) send("#{option}=", value) end end end
def override_client(name)
-
(String | Symbol)
- The global override.
Parameters:
-
name
(String | Symbol
) -- The name of the client.
Other tags:
- Example: Override the client globally. -
def override_client(name) Threaded.client_override = name ? name.to_s : nil end
def override_database(name)
-
(String | Symbol)
- The global override.
Parameters:
-
name
(String | Symbol
) -- The name of the database.
Other tags:
- Example: Override the database globally. -
def override_database(name) Threaded.database_override = name end
def purge!
-
(true)
- true.
Other tags:
- Note: - This is the fastest way to drop all data.
Other tags:
- Example: Purge all data. -
def purge! global_client.database.collections.each(&:drop) and true end
def register_model(klass)
-
klass
(Class
) -- The model to register.
Other tags:
- Example: Register a model. -
def register_model(klass) LOCK.synchronize do models.push(klass) unless models.include?(klass) end end
def running_with_passenger?
Returns:
-
(true | false)
- If the app is deployed on Passenger.
Other tags:
- Example: Is the application using passenger? -
def running_with_passenger? @running_with_passenger ||= defined?(PhusionPassenger) end
def set_log_levels
def set_log_levels Mongoid.logger.level = Mongoid::Config.log_level unless defined?(::Rails) Mongo::Logger.logger.level = Mongoid.logger.level end
def time_zone
-
(String)
- The time zone.
Other tags:
- Example: Get the time zone. -
def time_zone use_utc? ? "UTC" : ::Time.zone end
def truncate!
-
(true)
- true.
Other tags:
- Note: - This will be slower than purge!
Other tags:
- Example: Truncate all collection data. -
def truncate! global_client.database.collections.each do |collection| collection.find.delete_many end and true end