Module: Mongoid::Sessions::ClassMethods
- Defined in:
- lib/mongoid/sessions.rb
Instance Method Summary collapse
-
#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.
-
#session_override ⇒ String, Symbol
Get the overridden session name.
-
#store_in(options) ⇒ Class
Give this model specific custom default storage options.
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.
105 106 107 |
# File 'lib/mongoid/sessions.rb', line 105 def collection mongo_session[collection_name] 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.
119 120 121 |
# File 'lib/mongoid/sessions.rb', line 119 def collection_name __collection_name__ end |
#database_name ⇒ Symbol
Get the default database name for this model.
131 132 133 |
# File 'lib/mongoid/sessions.rb', line 131 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).
145 146 147 |
# File 'lib/mongoid/sessions.rb', line 145 def database_override self..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
160 161 162 163 164 |
# File 'lib/mongoid/sessions.rb', line 160 def mongo_session session = __session__ session.use(database_override || current_database_name(session)) self. ? session.with(self.) : session 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).
176 177 178 |
# File 'lib/mongoid/sessions.rb', line 176 def session_override self..try { |opts| opts[:session] } || Threaded.session_override end |
#store_in(options) ⇒ Class
Give this model specific custom default storage options.
215 216 217 218 219 |
# File 'lib/mongoid/sessions.rb', line 215 def store_in() Validators::Storage.validate(self, ) self. ||= {} self..merge!() end |