module Mongoid::Clients::Options::ClassMethods
Public Instance Methods
Get the database client name for the current persistence context of the document class.
@example Get the client name for the current persistence context.
Model.client_name
@return [ String ] The database client name for the current
persistence context.
# File lib/mongoid/clients/options.rb, line 146 def client_name persistence_context.client_name end
Get the collection for the current persistence context of the document class.
@example Get the collection for the current persistence context.
Model.collection
@return [ Mongo::Collection ] The collection for the current
persistence context.
# File lib/mongoid/clients/options.rb, line 182 def collection persistence_context.collection end
Get the collection name for the current persistence context of the document class.
@example Get the collection name for the current persistence context.
Model.collection_name
@return [ String ] The collection name for the current persistence
context.
# File lib/mongoid/clients/options.rb, line 158 def collection_name persistence_context.collection_name end
Get the database name for the current persistence context of the document class.
@example Get the database name for the current persistence context.
Model.database_name
@return [ String ] The database name for the current persistence
context.
# File lib/mongoid/clients/options.rb, line 170 def database_name persistence_context.database_name end
Get the client for the current persistence context of the document class.
@example Get the client for the current persistence context.
Model.mongo_client
@return [ Mongo::Client ] The client for the current persistence
context.
# File lib/mongoid/clients/options.rb, line 194 def mongo_client persistence_context.client end
Get the current persistence context of the document class. If a persistence context is not set, a new one will be initialized and returned.
@example Get the current persistence context.
Model.persistence_context
@return [ Mongoid::PersistenceContent ] The current persistence
context.
# File lib/mongoid/clients/options.rb, line 228 def persistence_context PersistenceContext.get(self) || PersistenceContext.new(self) end
Change the persistence context for this class during the block.
@example Save the current document to a different collection.
Model.with(collection: "bands") do |m| m.create end
@param [ Hash ] options The storage options.
@option options [ String | Symbol ] :collection The collection name. @option options [ String | Symbol ] :database The database name. @option options [ String | Symbol ] :client The client name.
# File lib/mongoid/clients/options.rb, line 210 def with(options, &block) original_context = PersistenceContext.get(self) original_cluster = persistence_context.cluster PersistenceContext.set(self, options) yield self ensure PersistenceContext.clear(self, original_cluster, original_context) end