module Mongoid::Sessions::Options

Public Instance Methods

collection_name() click to toggle source
# File lib/mongoid/sessions/options.rb, line 46
def collection_name
  if persistence_options && v = persistence_options[:collection]
    return v.to_sym
  end
end
mongo_session() click to toggle source
# File lib/mongoid/sessions/options.rb, line 39
def mongo_session
  if persistence_options
    session_name = persistence_options[:session] || self.class.session_name
    Sessions.with_name(session_name).with(persistence_options)
  end
end
persistence_options() click to toggle source
# File lib/mongoid/sessions/options.rb, line 35
def persistence_options
  @persistence_options
end
with(options) click to toggle source

Tell the next persistance operation to store in a specific collection, database or session.

@example Save the current document to a different collection.

model.with(collection: "secondary").save

@example Save the current document to a different database.

model.with(database: "secondary").save

@example Save the current document to a different session.

model.with(session: "replica_set").save

@example Save with a combination of options.

model.with(session: "sharded", database: "secondary").save

@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 ] :session The session name.

@return [ Document ] The current document.

@since 3.0.0

# File lib/mongoid/sessions/options.rb, line 30
def with(options)
  @persistence_options = options
  self
end