Module: Mongoid::Clients
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Clients::Sessions::ClassMethods ,
Clients::Options::ClassMethods ,
Clients::StorageOptions::ClassMethods ,
ActiveSupport::Concern
|
|
Instance Chain:
|
|
Defined in: | lib/mongoid/clients.rb, lib/mongoid/clients/factory.rb, lib/mongoid/clients/options.rb, lib/mongoid/clients/sessions.rb, lib/mongoid/clients/storage_options.rb, lib/mongoid/clients/validators/storage.rb |
Overview
Mixin module included into Document
which adds database client connection functionality. Also contains singleton class methods related to managing database clients.
Constant Summary
-
CREATE_LOCK =
# File 'lib/mongoid/clients.rb', line 108Mutex.new
StorageOptions
- Attributes & Methods
Class Attribute Summary
Clients::Sessions::ClassMethods
- Extended
in_transaction? | This method should be used to detect whether a persistence operation is executed inside transaction or not. |
Class Method Summary
-
.clear ⇒ Array
Clear all clients from the current thread.
-
.clients ⇒ Hash<Symbol, Mongo::Client>
Returns the stored clients indexed by name.
-
.default ⇒ Mongo::Client
Get the default client.
-
.disconnect ⇒ true
Disconnect all active clients.
-
.reconnect ⇒ true
Reconnect all active clients.
-
.set(name, client) ⇒ Mongo::Client
Store a client with the provided name.
-
.with_name(name) ⇒ Mongo::Client
Get a stored client with the provided name.
Clients::Sessions::ClassMethods
- Extended
after_commit | Sets up a callback is called after a commit of a transaction. |
after_create_commit | Shortcut for after_commit |
after_destroy_commit | Shortcut for after_commit |
after_rollback | This callback is called after a create, update, or destroy are rolled back. |
after_save_commit | Shortcut for after_commit |
after_update_commit | Shortcut for after_commit |
transaction | Executes a block within the context of a transaction. |
with_session | Execute a block within the context of a session. |
_session, | |
assert_valid_transaction_action | Asserts that the given actions are valid for after_commit and after_rollback callbacks. |
run_abort_callbacks | Runs after_rollback callbacks on modified documents. |
run_commit_callbacks | Runs after_commit callbacks on modified documents. |
set_options_for_callbacks! | Transforms custom options for after_commit and after_rollback callbacks into options for |
transaction_include_any_action?, | |
transactions_not_supported_exceptions | Driver version 2.20 introduced a new exception for reporting that transactions are not supported. |
Clients::Options::ClassMethods
- Extended
client_name | Get the database client name for the current persistence context of the document class. |
collection | Get the collection for the current persistence context of the document class. |
collection_name | Get the collection name for the current persistence context of the document class. |
database_name | Get the database name for the current persistence context of the document class. |
mongo_client | Get the client for the current persistence context of the document class. |
persistence_context | Get the current persistence context of the document class. |
with | Change the persistence context for this class during the block. |
Clients::StorageOptions::ClassMethods
- Extended
reset_storage_options! | Reset the store_in options. |
storage_options_defaults | Get the default storage options. |
store_in | Give this model specific custom default storage options. |
Instance Attribute Summary
Options
- Included
#persistence_context | Get the document’s current persistence context. |
#persistence_context? | Returns whether a persistence context is set for the document or the document’s class. |
StorageOptions
- Included
#remembered_storage_options | Remembers the storage options that were active when the current object was instantiated/created. |
Instance Method Summary
Sessions
- Included
#ensure_client_compatibility! | If at least one session is active, this ensures that the current model’s client is compatible with one of them. |
Options
- Included
#collection | Get the collection for the document’s current persistence context. |
#collection_name | Get the collection name for the document’s current persistence context. |
#mongo_client | Get the database client for the document’s current persistence context. |
#with | Change the persistence context for this object during the block. |
#clear_persistence_context, #default_storage_options, #set_persistence_context |
StorageOptions
- Included
#remember_storage_options! | Saves the storage options from the current persistence context. |
#storage_options | The storage options that apply to this record, consisting of both the class-level declared storage options (e.g. |
Class Attribute Details
.storage_options (rw)
[ GitHub ]# File 'lib/mongoid/clients/storage_options.rb', line 14
class_attribute :, instance_accessor: false, default:
.storage_options? ⇒ Boolean (rw)
[ GitHub ]# File 'lib/mongoid/clients/storage_options.rb', line 14
class_attribute :, instance_accessor: false, default:
Class Method Details
.clear ⇒ Array
Clear all clients from the current thread.
# File 'lib/mongoid/clients.rb', line 29
def clear clients.clear end
.clients ⇒ Hash<Symbol, Mongo::Client
>
Returns the stored clients indexed by name.
# File 'lib/mongoid/clients.rb', line 102
def clients @clients ||= {} end
.default ⇒ Mongo::Client
Get the default client.
# File 'lib/mongoid/clients.rb', line 39
def default with_name(:default) end
.disconnect ⇒ true
Disconnect all active clients.
# File 'lib/mongoid/clients.rb', line 49
def disconnect clients.each_value(&:close) true end
.reconnect ⇒ true
Reconnect all active clients.
# File 'lib/mongoid/clients.rb', line 60
def reconnect clients.each_value(&:reconnect) true end
.set(name, client) ⇒ Mongo::Client
Store a client with the provided name.
.with_name(name) ⇒ Mongo::Client
Get a stored client with the provided name. If no client exists with the given name, a new one will be created, stored, and returned.
# File 'lib/mongoid/clients.rb', line 75
def with_name(name) name_as_symbol = name.to_sym return clients[name_as_symbol] if clients[name_as_symbol] CREATE_LOCK.synchronize do if (key_vault_client = Mongoid.clients.dig(name_as_symbol, :, :, :key_vault_client)) clients[key_vault_client.to_sym] ||= Clients::Factory.create(key_vault_client) end clients[name_as_symbol] ||= Clients::Factory.create(name) end end