Included Modules

Class/Module Index [+]

Quicksearch

Mongoid::Config

This module defines all the configuration options for Mongoid, including the database connections.

Public Instance Methods

configured?() click to toggle source

Has Mongoid been configured? This is checking that at least a valid session config exists.

@example Is Mongoid configured?

config.configured?

@return [ true, false ] If Mongoid is configured.

@since 3.0.9

# File lib/mongoid/config.rb, line 37
def configured?
  sessions.has_key?(:default)
end
connect_to(name, options = { consistency: :eventual }) click to toggle source

Connect to the provided database name on the default session.

@note Use only in development or test environments for convenience.

@example Set the database to connect to.

config.connect_to("mongoid_test")

@param [ String ] name The database name.

@since 3.0.0

# File lib/mongoid/config.rb, line 51
def connect_to(name, options = { consistency: :eventual })
  self.sessions = {
    default: {
      database: name,
      hosts: [ "localhost:27017" ],
      options: options
    }
  }
end
destructive_fields() click to toggle source

Return field names that could cause destructive things to happen if defined in a Mongoid::Document.

@example Get the destructive fields.

config.destructive_fields

@return [ Array<String> ] An array of bad field names.

# File lib/mongoid/config.rb, line 68
def destructive_fields
  Components.prohibited_methods
end
load!(path, environment = nil) click to toggle source

Load the settings from a compliant mongoid.yml file. This can be used for easy setup with frameworks other than Rails.

@example Configure Mongoid.

Mongoid.load!("/path/to/mongoid.yml")

@param [ String ] path The path to the file. @param [ String, Symbol ] environment The environment to load.

@since 2.0.1

# File lib/mongoid/config.rb, line 82
def load!(path, environment = nil)
  settings = Environment.load_yaml(path, environment)
  load_configuration(settings) if settings.present?
  settings
end
options=(options) click to toggle source

Set the configuration options. Will validate each one individually.

@example Set the options.

config.options = { raise_not_found_error: true }

@param [ Hash ] options The configuration options.

@since 3.0.0

# File lib/mongoid/config.rb, line 138
def options=(options)
  if options
    options.each_pair do |option, value|
      Validators::Option.validate(option)
      send("#{option}=", value)
    end
  end
end
override_database(name) click to toggle source

Override the database to use globally.

@example Override the database globally.

config.override_database(:optional)

@param [ String, Symbol ] name The name of the database.

@return [ String, Symbol ] The global override.

@since 3.0.0

# File lib/mongoid/config.rb, line 98
def override_database(name)
  Threaded.database_override = name
end
override_session(name) click to toggle source

Override the session to use globally.

@example Override the session globally.

config.override_session(:optional)

@param [ String, Symbol ] name The name of the session.

@return [ String, Symbol ] The global override.

@since 3.0.0

# File lib/mongoid/config.rb, line 112
def override_session(name)
  Threaded.session_override = name ? name.to_s : nil
end
purge!() click to toggle source

Purge all data in all collections, including indexes.

@example Purge all data.

Mongoid::Config.purge!

@return [ true ] true.

@since 2.0.2

# File lib/mongoid/config.rb, line 124
def purge!
  Sessions.default.collections.each do |collection|
    collection.drop
  end and true
end
running_with_passenger?() click to toggle source

Is the application running under passenger?

@example Is the application using passenger?

config.running_with_passenger?

@return [ true, false ] If the app is deployed on Passenger.

@since 3.0.11

# File lib/mongoid/config.rb, line 155
def running_with_passenger?
  @running_with_passenger ||= defined?(PhusionPassenger)
end
sessions() click to toggle source

Get the session configuration or an empty hash.

@example Get the sessions configuration.

config.sessions

@return [ Hash ] The sessions configuration.

@since 3.0.0

# File lib/mongoid/config.rb, line 167
def sessions
  @sessions ||= {}
end
sessions=(sessions) click to toggle source

Set the session configuration options.

@example Set the session configuration options.

config.sessions = { default: { hosts: [ "localhost:27017" ] }}

@param [ Hash ] sessions The configuration options.

@since 3.0.0

# File lib/mongoid/config.rb, line 179
def sessions=(sessions)
  raise Errors::NoSessionsConfig.new unless sessions
  sess = sessions.with_indifferent_access
  Validators::Session.validate(sess)
  @sessions = sess
  sess
end
time_zone() click to toggle source

Get the time zone to use.

@example Get the time zone.

Config.time_zone

@return [ String ] The time zone.

@since 3.0.0

# File lib/mongoid/config.rb, line 195
def time_zone
  use_utc? ? "UTC" : ::Time.zone
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.