Module: Mongoid::Clients::Factory

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

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:



22
23
24
25
26
27
# File 'build/mongoid-8.1/lib/mongoid/clients/factory.rb', line 22

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:



38
39
40
# File 'build/mongoid-8.1/lib/mongoid/clients/factory.rb', line 38

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