Class: Mongoid::Config::Database

Inherits:
Hash show all
Defined in:
lib/mongoid/config/database.rb

Overview

This class handles the configuration and initialization of a mongodb database from options.

Instance Method Summary collapse

Methods included from Extensions::Hash::Scoping

#as_conditions

Methods included from Extensions::Hash::CriteriaHelpers

#expand_complex_criteria, #extract_id

Methods included from Extensions::Hash::DeepCopy

#_deep_copy

Constructor Details

#initialize(options = {}) ⇒ Database

Create the new db configuration class.

Examples:

Initialize the class.

Config::Database.new(
  false, "uri" => { "mongodb://durran:password@localhost:27017/mongoid" }
)

Parameters:

  • options (Hash) (defaults to: {})

    The configuration options.

Options Hash (options):

  • :database (String)

    The database name.

  • :host (String)

    The database host.

  • :password (String)

    The password for authentication.

  • :port (Integer)

    The port for the database.

  • :uri (String)

    The uri for the database.

  • :username (String)

    The user for authentication.

Since:

  • 2.0.0.rc.1



39
40
41
# File 'lib/mongoid/config/database.rb', line 39

def initialize(options = {})
  merge!(options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)

Convenience for accessing the hash via dot notation.

Examples:

Access a value in alternate syntax.

db.host

Returns:

  • (Object)

    The value in the hash.

Since:

  • 2.0.0.rc.1



129
130
131
# File 'lib/mongoid/config/database.rb', line 129

def method_missing(name, *args, &block)
  self[name.to_s]
end

Instance Method Details

#configureArray<Mongo::DB, Array<Mongo:DB>>

Configure the database connections. This will return an array containing the master and an array of slaves.

Examples:

Configure the connection.

db.configure

Returns:

  • (Array<Mongo::DB, Array<Mongo:DB>>)

    The Mongo databases.

Since:

  • 2.0.0.rc.1



18
19
20
# File 'lib/mongoid/config/database.rb', line 18

def configure
  [ master.db(name), slaves.map { |slave| slave.db(name) } ]
end