Module: Mongoid::Sessions

Extended by:
ActiveSupport::Concern
Includes:
Options, StorageOptions, ThreadOptions
Included in:
Composable
Defined in:
lib/mongoid/sessions.rb,
lib/mongoid/sessions/options.rb,
lib/mongoid/sessions/factory.rb,
lib/mongoid/sessions/mongo_uri.rb,
lib/mongoid/sessions/thread_options.rb,
lib/mongoid/sessions/storage_options.rb,
lib/mongoid/sessions/validators/storage.rb

Defined Under Namespace

Modules: ClassMethods, Factory, Options, StorageOptions, ThreadOptions, Validators Classes: MongoUri

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Options

#persistence_options, #with

Class Method Details

+ (Array) clear

Clear all sessions from the current thread.

Examples:

Clear all sessions.

Mongoid::Sessions.clear

Returns:

  • (Array)

    The empty sessions.

Since:

  • 3.0.0



24
25
26
# File 'lib/mongoid/sessions.rb', line 24

def clear
  Threaded.sessions.clear
end

+ (Moped::Session) default

Get the default session.

Examples:

Get the default session.

Mongoid::Sessions.default

Returns:

  • (Moped::Session)

    The default session.

Since:

  • 3.0.0



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

def default
  Threaded.sessions[:default] ||= Sessions::Factory.default
end

+ (true) disconnect

Disconnect all active sessions.

Examples:

Disconnect all active sessions.

Mongoid::Sessions.disconnect

Returns:

  • (true)

    True.

Since:

  • 3.1.0



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

def disconnect
  Threaded.sessions.values.each do |session|
    session.disconnect
  end
end

+ (Moped::Session) with_name(name)

Get a session with the provided name.

Examples:

Get a session with the name.

Mongoid::Sessions.with_name(:replica)

Parameters:

  • name (Symbol)

    The name of the session.

Returns:

  • (Moped::Session)

    The named session.

Since:

  • 3.0.0



64
65
66
# File 'lib/mongoid/sessions.rb', line 64

def with_name(name)
  Threaded.sessions[name.to_sym] ||= Sessions::Factory.create(name)
end

Instance Method Details

- (Moped::Collection) collection

Get the collection for this model from the session. Will check for an overridden collection name from the store_in macro or the collection with a pluralized model name.

Examples:

Get the model's collection.

Model.collection

Returns:

  • (Moped::Collection)

    The collection.

Since:

  • 3.0.0



79
80
81
# File 'lib/mongoid/sessions.rb', line 79

def collection
  mongo_session[collection_name]
end

- (Object) collection_name



87
88
89
# File 'lib/mongoid/sessions.rb', line 87

def collection_name
  super || self.class.collection_name
end

- (Object) mongo_session



83
84
85
# File 'lib/mongoid/sessions.rb', line 83

def mongo_session
  super || self.class.mongo_session
end