Module: Mongoid::Clients
- Extended by:
- ActiveSupport::Concern
- 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
-
.clear ⇒ Array
Clear all clients from the current thread.
- .clients ⇒ Object
-
.default ⇒ Mongo::Client
Get the default client.
-
.disconnect ⇒ true
Disconnect all active clients.
- .set(name, client) ⇒ Object
-
.with_name(name) ⇒ Mongo::Client
Get a client with the provided name.
Instance Method Summary collapse
-
#collection ⇒ Mongo::Collection
Get the collection for this model from the client.
- #collection_name ⇒ Object
- #mongo_client ⇒ Object
Methods included from Options
Class Method Details
.clear ⇒ Array
Clear all clients from the current thread.
25 26 27 |
# File 'lib/mongoid/clients.rb', line 25 def clear clients.clear end |
.clients ⇒ Object
73 74 75 |
# File 'lib/mongoid/clients.rb', line 73 def clients @clients ||= {} end |
.default ⇒ Mongo::Client
Get the default client.
37 38 39 |
# File 'lib/mongoid/clients.rb', line 37 def default clients[:default] ||= Clients::Factory.default end |
.disconnect ⇒ true
Disconnect all active clients.
49 50 51 52 53 |
# File 'lib/mongoid/clients.rb', line 49 def disconnect clients.values.each do |client| client.close end end |
.set(name, client) ⇒ Object
69 70 71 |
# File 'lib/mongoid/clients.rb', line 69 def set(name, client) clients[name.to_sym] = client end |
Instance Method Details
#collection ⇒ Mongo::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.
88 89 90 |
# File 'lib/mongoid/clients.rb', line 88 def collection mongo_client[collection_name] end |
#collection_name ⇒ Object
96 97 98 |
# File 'lib/mongoid/clients.rb', line 96 def collection_name super || self.class.collection_name end |
#mongo_client ⇒ Object
92 93 94 |
# File 'lib/mongoid/clients.rb', line 92 def mongo_client super || self.class.mongo_client end |