Module: Mongoid::Sessions
- Extended by:
- ActiveSupport::Concern
- Includes:
- Options
- Included in:
- Composable
- Defined in:
- lib/mongoid/sessions.rb,
lib/mongoid/sessions/factory.rb,
lib/mongoid/sessions/options.rb,
lib/mongoid/sessions/mongo_uri.rb,
lib/mongoid/sessions/validators/storage.rb
Defined Under Namespace
Modules: ClassMethods, Factory, Options, Validators Classes: MongoUri
Class Method Summary collapse
-
.clear ⇒ Array
Clear all sessions from the current thread.
-
.default ⇒ Moped::Session
Get the default session.
-
.disconnect ⇒ true
Disconnect all active sessions.
-
.with_name(name) ⇒ Moped::Session
Get a session with the provided name.
Instance Method Summary collapse
-
#collection ⇒ Moped::Collection
Get the collection for this model from the session.
- #collection_name ⇒ Object
- #mongo_session ⇒ Object
Methods included from Options
Class Method Details
.clear ⇒ Array
Clear all sessions from the current thread.
26 27 28 |
# File 'lib/mongoid/sessions.rb', line 26 def clear Threaded.sessions.clear end |
.default ⇒ Moped::Session
Get the default session.
38 39 40 |
# File 'lib/mongoid/sessions.rb', line 38 def default Threaded.sessions[:default] ||= Sessions::Factory.default end |
.disconnect ⇒ true
Disconnect all active sessions.
50 51 52 53 54 |
# File 'lib/mongoid/sessions.rb', line 50 def disconnect Threaded.sessions.values.each do |session| session.disconnect end end |
Instance Method Details
#collection ⇒ Moped::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.
81 82 83 |
# File 'lib/mongoid/sessions.rb', line 81 def collection mongo_session[collection_name] end |
#collection_name ⇒ Object
89 90 91 |
# File 'lib/mongoid/sessions.rb', line 89 def collection_name .try { |opts| opts[:collection] } || self.class.collection_name end |
#mongo_session ⇒ Object
85 86 87 |
# File 'lib/mongoid/sessions.rb', line 85 def mongo_session ? self.class.mongo_session.with() : self.class.mongo_session end |