Module: Mongoid::Sessions::Options

Extended by:
ActiveSupport::Concern
Included in:
Criteria, Mongoid::Sessions
Defined in:
lib/mongoid/sessions/options.rb

Defined Under Namespace

Modules: ClassMethods, Threaded Classes: Proxy

Instance Method Summary collapse

Instance Method Details

#collection_nameObject



47
48
49
50
51
# File 'lib/mongoid/sessions/options.rb', line 47

def collection_name
  if persistence_options && v = persistence_options[:collection]
    return v.to_sym
  end
end

#mongo_sessionObject



40
41
42
43
44
45
# File 'lib/mongoid/sessions/options.rb', line 40

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_optionsObject



36
37
38
# File 'lib/mongoid/sessions/options.rb', line 36

def persistence_options
  @persistence_options
end

#with(options) ⇒ Document

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

Examples:

Save the current document to a different collection.

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

Save the current document to a different database.

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

Save the current document to a different session.

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

Save with a combination of options.

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

Parameters:

  • options (Hash)

    The storage options.

Options Hash (options):

  • :collection (String, Symbol)

    The collection name.

  • :database (String, Symbol)

    The database name.

  • :session (String, Symbol)

    The session name.

Returns:

Since:

  • 3.0.0



31
32
33
34
# File 'lib/mongoid/sessions/options.rb', line 31

def with(options)
  @persistence_options = options
  self
end