Module: Mongoid::Clients::Factory

Extended by:
Factory, Loggable
Included in:
Factory
Defined in:
lib/mongoid/clients/factory.rb

Overview

Factory used to create database clients.

Instance Method Summary collapse

Methods included from Loggable

logger, logger=

Instance Method Details

#create(name = nil) ⇒ Mongo::Client

Create a new client given the named configuration. If no name is provided, return a new client with the default configuration. If a name is provided for which no configuration exists, an error will be raised.

Examples:

Create the client.

Factory.create(:analytics)

Parameters:

  • name (String | Symbol) (defaults to: nil)

    The named client configuration.

Returns:

  • (Mongo::Client)

    The new client.

Raises:



25
26
27
28
29
30
# File 'lib/mongoid/clients/factory.rb', line 25

def create(name = nil)
  return default unless name
  config = Mongoid.clients[name]
  raise Errors::NoClientConfig.new(name) unless config
  create_client(config)
end

#defaultMongo::Client

Get the default client.

Examples:

Get the default client.

Factory.default

Returns:

  • (Mongo::Client)

    The default client.

Raises:



41
42
43
# File 'lib/mongoid/clients/factory.rb', line 41

def default
  create_client(Mongoid.clients[:default])
end