module Mongoid::Clients::Options::ClassMethods

Public Instance Methods

client_name() click to toggle source
# File lib/mongoid/clients/options.rb, line 63
def client_name
  persistence_context.client_name
end
collection() click to toggle source
# File lib/mongoid/clients/options.rb, line 75
def collection
  persistence_context.collection
end
collection_name() click to toggle source
# File lib/mongoid/clients/options.rb, line 67
def collection_name
  persistence_context.collection_name
end
database_name() click to toggle source
# File lib/mongoid/clients/options.rb, line 71
def database_name
  persistence_context.database_name
end
mongo_client() click to toggle source
# File lib/mongoid/clients/options.rb, line 79
def mongo_client
  persistence_context.client
end
persistence_context() click to toggle source
# File lib/mongoid/clients/options.rb, line 106
def persistence_context
  PersistenceContext.get(self) || PersistenceContext.new(self)
end
with(options) { |self| ... } click to toggle source

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.

@since 6.0.0

# File lib/mongoid/clients/options.rb, line 97
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