Module: Mongoid::Sessions::ClassMethods
- Defined in:
- lib/mongoid/sessions.rb
Instance Method Summary collapse
-
#clear_persistence_options ⇒ true
Clear all persistence options from the current thread.
-
#collection ⇒ Moped::Collection
Get the collection for this model from the session.
-
#collection_name ⇒ Symbol
Get the name of the collection this model persists to.
-
#database_name ⇒ Symbol
Get the default database name for this model.
-
#database_override ⇒ String, Symbol
Get the overridden database name.
-
#mongo_session ⇒ Moped::Session
Get the session for this model.
-
#persistence_options ⇒ Hash
Get the persistence options from the current thread.
-
#session_override ⇒ String, Symbol
Get the overridden session name.
-
#store_in(options) ⇒ Class
Give this model specific custom default storage options.
-
#with(options) ⇒ Class
Tell the next persistance operation to store in a specific collection, database or session.
Instance Method Details
#clear_persistence_options ⇒ true
Clear all persistence options from the current thread.
151 152 153 |
# File 'lib/mongoid/sessions.rb', line 151 def Threaded.(self) end |
#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.
165 166 167 168 169 170 171 172 173 |
# File 'lib/mongoid/sessions.rb', line 165 def collection if opts = coll = mongo_session.with(opts)[opts[:collection] || collection_name] unless validating_with_query? || _loading_revision? coll else mongo_session[collection_name] end end |
#collection_name ⇒ Symbol
Get the name of the collection this model persists to. This will be either the pluralized class name or the option defined in the store_in macro.
185 186 187 |
# File 'lib/mongoid/sessions.rb', line 185 def collection_name __collection_name__ end |
#database_name ⇒ Symbol
Get the default database name for this model.
197 198 199 |
# File 'lib/mongoid/sessions.rb', line 197 def database_name __database_name__ end |
#database_override ⇒ String, Symbol
Get the overridden database name. This either can be overridden by using Model.with
or by overriding at the global level via Mongoid.override_database(:name).
211 212 213 |
# File 'lib/mongoid/sessions.rb', line 211 def database_override .try { |opts| opts[:database] } || Threaded.database_override end |
#mongo_session ⇒ Moped::Session
Get the session for this model. This is determined in the following order:
1. Any custom configuration provided by the 'store_in' macro.
2. The 'default' session as provided in the mongoid.yml
226 227 228 229 230 |
# File 'lib/mongoid/sessions.rb', line 226 def mongo_session session = __session__ session.use(database_override || current_database_name(session)) session end |
#persistence_options ⇒ Hash
Get the persistence options from the current thread.
240 241 242 |
# File 'lib/mongoid/sessions.rb', line 240 def Threaded.(self) end |
#session_override ⇒ String, Symbol
Get the overridden session name. This either can be overridden by using Model.with
or by overriding at the global level via Mongoid.override_session(:name).
254 255 256 |
# File 'lib/mongoid/sessions.rb', line 254 def session_override .try { |opts| opts[:session] } || Threaded.session_override end |
#store_in(options) ⇒ Class
Give this model specific custom default storage options.
293 294 295 296 297 |
# File 'lib/mongoid/sessions.rb', line 293 def store_in() Validators::Storage.validate(self, ) self. ||= {} self..merge!() end |
#with(options) ⇒ Class
Tell the next persistance operation to store in a specific collection, database or session.
323 324 325 326 |
# File 'lib/mongoid/sessions.rb', line 323 def with() Threaded.(self, ) self end |