Module: Mongoid::Clients

Extended by:
ActiveSupport::Concern
Includes:
Options, Sessions, StorageOptions
Included in:
Composable
Defined in:
build/mongoid-master/lib/mongoid/clients.rb,
build/mongoid-master/lib/mongoid/clients/factory.rb,
build/mongoid-master/lib/mongoid/clients/options.rb,
build/mongoid-master/lib/mongoid/clients/sessions.rb,
build/mongoid-master/lib/mongoid/clients/storage_options.rb,
build/mongoid-master/lib/mongoid/clients/validators/storage.rb

Defined Under Namespace

Modules: Factory, Options, Sessions, StorageOptions, Validators

Class Method Summary collapse

Methods included from Sessions

#with_session

Methods included from Options

#collection, #collection_name, #mongo_client, #persistence_context, #with

Class Method Details

.clearArray

Clear all clients from the current thread.

Examples:

Clear all clients.

Mongoid::Clients.clear

Returns:

  • (Array)

    The empty clients.

Since:

  • 3.0.0



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

def clear
  clients.clear
end

.clientsObject



79
80
81
# File 'build/mongoid-master/lib/mongoid/clients.rb', line 79

def clients
  @clients ||= {}
end

.defaultMongo::Client

Get the default client.

Examples:

Get the default client.

Mongoid::Clients.default

Returns:

  • (Mongo::Client)

    The default client.

Since:

  • 3.0.0



39
40
41
# File 'build/mongoid-master/lib/mongoid/clients.rb', line 39

def default
  with_name(:default)
end

.disconnecttrue

Disconnect all active clients.

Examples:

Disconnect all active clients.

Mongoid::Clients.disconnect

Returns:

  • (true)

    True.

Since:

  • 3.1.0



51
52
53
54
55
# File 'build/mongoid-master/lib/mongoid/clients.rb', line 51

def disconnect
  clients.values.each do |client|
    client.close
  end
end

.set(name, client) ⇒ Object



75
76
77
# File 'build/mongoid-master/lib/mongoid/clients.rb', line 75

def set(name, client)
  clients[name.to_sym] = client
end

.with_name(name) ⇒ Mongo::Client

Get a client with the provided name.

Examples:

Get a client with the name.

Mongoid::Clients.with_name(:replica)

Parameters:

  • name (Symbol)

    The name of the client.

Returns:

  • (Mongo::Client)

    The named client.

Since:

  • 3.0.0



67
68
69
70
71
72
73
# File 'build/mongoid-master/lib/mongoid/clients.rb', line 67

def with_name(name)
  name_as_symbol = name.to_sym
  return clients[name_as_symbol] if clients[name_as_symbol]
  CREATE_LOCK.synchronize do
    clients[name_as_symbol] ||= Clients::Factory.create(name)
  end
end