Module: Mongoid::Clients::Factory

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

Instance Method Summary collapse

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(:secondary)

Parameters:

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

    The named client configuration.

Returns:

  • (Mongo::Client)

    The new client.

Raises:

Since:

  • 3.0.0



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

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:

Since:

  • 3.0.0



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

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