Module: Mongoid::Clients

Extended by:
ActiveSupport::Concern, Gem::Deprecate
Includes:
Options, StorageOptions, ThreadOptions
Included in:
Composable
Defined in:
lib/mongoid/clients.rb,
lib/mongoid/clients/factory.rb,
lib/mongoid/clients/options.rb,
lib/mongoid/clients/thread_options.rb,
lib/mongoid/clients/storage_options.rb,
lib/mongoid/clients/validators/storage.rb

Defined Under Namespace

Modules: ClassMethods, Factory, Options, StorageOptions, ThreadOptions, Validators

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Options

#persistence_options, #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



26
27
28
# File 'lib/mongoid/clients.rb', line 26

def clear
  clients.clear
end

.clientsObject



74
75
76
# File 'lib/mongoid/clients.rb', line 74

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



38
39
40
# File 'lib/mongoid/clients.rb', line 38

def default
  clients[:default] ||= Clients::Factory.default
end

.disconnecttrue

Disconnect all active clients.

Examples:

Disconnect all active clients.

Mongoid::Clients.disconnect

Returns:

  • (true)

    True.

Since:

  • 3.1.0



50
51
52
53
54
# File 'lib/mongoid/clients.rb', line 50

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

.set(name, client) ⇒ Object



70
71
72
# File 'lib/mongoid/clients.rb', line 70

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



66
67
68
# File 'lib/mongoid/clients.rb', line 66

def with_name(name)
  clients[name.to_sym] ||= Clients::Factory.create(name)
end

Instance Method Details

#collectionMongo::Collection

Get the collection for this model from the client. Will check for an overridden collection name from the store_in macro or the collection with a pluralized model name.

Examples:

Get the model’s collection.

Model.collection

Returns:

  • (Mongo::Collection)

    The collection.

Since:

  • 3.0.0



89
90
91
# File 'lib/mongoid/clients.rb', line 89

def collection
  mongo_client[collection_name]
end

#collection_nameObject



99
100
101
# File 'lib/mongoid/clients.rb', line 99

def collection_name
  super || self.class.collection_name
end

#mongo_clientObject Also known as: mongo_session



93
94
95
# File 'lib/mongoid/clients.rb', line 93

def mongo_client
  super || self.class.mongo_client
end