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
-
.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 (also: #mongo_session)
Methods included from Options
Class Method Details
.clear ⇒ Array
Clear all clients from the current thread.
26 27 28 |
# File 'lib/mongoid/clients.rb', line 26 def clear clients.clear end |
.clients ⇒ Object
74 75 76 |
# File 'lib/mongoid/clients.rb', line 74 def clients @clients ||= {} end |
.default ⇒ Mongo::Client
Get the default client.
38 39 40 |
# File 'lib/mongoid/clients.rb', line 38 def default clients[:default] ||= Clients::Factory.default end |
.disconnect ⇒ true
Disconnect all active clients.
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 |
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.
89 90 91 |
# File 'lib/mongoid/clients.rb', line 89 def collection mongo_client[collection_name] end |
#collection_name ⇒ Object
99 100 101 |
# File 'lib/mongoid/clients.rb', line 99 def collection_name super || self.class.collection_name end |
#mongo_client ⇒ Object Also known as: mongo_session
93 94 95 |
# File 'lib/mongoid/clients.rb', line 93 def mongo_client super || self.class.mongo_client end |