Module: Mongoid::Clients::Factory

Extended by:
Factory
Included in:
Factory
Defined in:
build/mongoid-master/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(:analytics)

Parameters:

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

    The named client configuration.

Returns:

  • (Mongo::Client)

    The new client.

Raises:

Since:

  • 3.0.0



24
25
26
27
28
29
# File 'build/mongoid-master/lib/mongoid/clients/factory.rb', line 24

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



42
43
44
# File 'build/mongoid-master/lib/mongoid/clients/factory.rb', line 42

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