module Mongoid::Clients::Options
Public Instance Methods
collection(parent = nil)
click to toggle source
# File lib/mongoid/clients/options.rb, line 30 def collection(parent = nil) persistence_context.collection(parent) end
collection_name()
click to toggle source
# File lib/mongoid/clients/options.rb, line 34 def collection_name persistence_context.collection_name end
mongo_client()
click to toggle source
# File lib/mongoid/clients/options.rb, line 38 def mongo_client persistence_context.client end
persistence_context()
click to toggle source
# File lib/mongoid/clients/options.rb, line 42 def persistence_context PersistenceContext.get(self) || PersistenceContext.get(self.class) || PersistenceContext.new(self.class) end
with(options_or_context) { |self| ... }
click to toggle source
Change the persistence context for this object during the block.
@example Save the current document to a different collection.
model.with(collection: "secondary") do |m| m.save end
@param [ Hash, Mongoid::PersistenceContext
] options_or_context
The storage options or a persistence context.
@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 22 def with(options_or_context, &block) original_cluster = persistence_context.cluster set_persistence_context(options_or_context) yield self ensure clear_persistence_context(original_cluster) end
Private Instance Methods
clear_persistence_context(original_cluster = nil)
click to toggle source
# File lib/mongoid/clients/options.rb, line 54 def clear_persistence_context(original_cluster = nil) PersistenceContext.clear(self, original_cluster) end
set_persistence_context(options_or_context)
click to toggle source
# File lib/mongoid/clients/options.rb, line 50 def set_persistence_context(options_or_context) PersistenceContext.set(self, options_or_context) end