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.
137 138 139 |
# File 'lib/mongoid/sessions.rb', line 137 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.
151 152 153 154 155 156 157 158 159 |
# File 'lib/mongoid/sessions.rb', line 151 def collection if opts = coll = mongo_session.with(opts)[opts[:collection] || collection_name] 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.
171 172 173 |
# File 'lib/mongoid/sessions.rb', line 171 def collection_name @collection_name ||= __collection_name__ end |
#database_name ⇒ Symbol
Get the default database name for this model.
183 184 185 |
# File 'lib/mongoid/sessions.rb', line 183 def database_name @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).
197 198 199 |
# File 'lib/mongoid/sessions.rb', line 197 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
212 213 214 215 216 |
# File 'lib/mongoid/sessions.rb', line 212 def mongo_session session = __session__ session.use(database_override || database_name) session end |
#persistence_options ⇒ Hash
Get the persistence options from the current thread.
226 227 228 |
# File 'lib/mongoid/sessions.rb', line 226 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).
240 241 242 |
# File 'lib/mongoid/sessions.rb', line 240 def session_override .try { |opts| opts[:session] } || Threaded.session_override end |
#store_in(options) ⇒ Class
Give this model specific custom default storage options.
279 280 281 282 283 |
# File 'lib/mongoid/sessions.rb', line 279 def store_in() Validators::Storage.validate(self, ) @collection_name, @database_name = nil, nil self. = end |
#with(options) ⇒ Class
Tell the next persistance operation to store in a specific collection, database or session.
309 310 311 312 |
# File 'lib/mongoid/sessions.rb', line 309 def with() Threaded.(self, ) self end |