module Mongoid::Clients
Constants
- CREATE_LOCK
Public Class Methods
clear()
click to toggle source
Clear all clients from the current thread.
@example Clear all clients.
Mongoid::Clients.clear
@return [ Array ] The empty clients.
@since 3.0.0
# File lib/mongoid/clients.rb, line 27 def clear clients.clear end
clients()
click to toggle source
# File lib/mongoid/clients.rb, line 79 def clients @clients ||= {} end
default()
click to toggle source
Get the default client.
@example Get the default client.
Mongoid::Clients.default
@return [ Mongo::Client ] The default client.
@since 3.0.0
# File lib/mongoid/clients.rb, line 39 def default with_name(:default) end
disconnect()
click to toggle source
Disconnect all active clients.
@example Disconnect all active clients.
Mongoid::Clients.disconnect
@return [ true ] True.
@since 3.1.0
# File lib/mongoid/clients.rb, line 51 def disconnect clients.values.each do |client| client.close end end
set(name, client)
click to toggle source
# File lib/mongoid/clients.rb, line 75 def set(name, client) clients[name.to_sym] = client end
with_name(name)
click to toggle source
Get a client with the provided name.
@example Get a client with the name.
Mongoid::Clients.with_name(:replica)
@param [ String | Symbol ] name The name of the client.
@return [ Mongo::Client ] The named client.
@since 3.0.0
# File 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