Top Level Namespace
- Extended by:
- Mongoid::Extensions::Array::ClassMethods, Mongoid::Extensions::BigDecimal::ClassMethods, Mongoid::Extensions::Date::ClassMethods, Mongoid::Extensions::DateTime::ClassMethods, Mongoid::Extensions::Float::ClassMethods, Mongoid::Extensions::Hash::ClassMethods, Mongoid::Extensions::Integer::ClassMethods, Mongoid::Extensions::Object::ClassMethods, Mongoid::Extensions::Range::ClassMethods, Mongoid::Extensions::Regexp::ClassMethods, Mongoid::Extensions::Set::ClassMethods, Mongoid::Extensions::String::ClassMethods, Mongoid::Extensions::Symbol::ClassMethods, Mongoid::Extensions::Time::ClassMethods
Defined Under Namespace
Instance Method Summary collapse
-
#check_if_transactions_might_be_available!(client) ⇒ Object
This method raises an error if the cluster the client is connected to does not support transactions in any case.
-
#start_sandbox ⇒ Object
Prepares console sandbox mode.
-
#start_sandbox_transaction(client) ⇒ Object
Starts a transaction that should include all the operations inside the sandboxed console session.
Methods included from Mongoid::Extensions::Set::ClassMethods
Methods included from Mongoid::Extensions::Date::ClassMethods
Methods included from Mongoid::Extensions::Hash::ClassMethods
Methods included from Mongoid::Extensions::Time::ClassMethods
configured, demongoize, mongoize
Methods included from Mongoid::Extensions::Array::ClassMethods
__mongoize_fk__, mongoize, resizable?
Methods included from Mongoid::Extensions::Float::ClassMethods
Methods included from Mongoid::Extensions::Range::ClassMethods
Methods included from Mongoid::Extensions::Object::ClassMethods
__mongoize_fk__, demongoize, mongoize
Methods included from Mongoid::Extensions::Regexp::ClassMethods
Methods included from Mongoid::Extensions::String::ClassMethods
Methods included from Mongoid::Extensions::Symbol::ClassMethods
Methods included from Mongoid::Extensions::Integer::ClassMethods
Methods included from Mongoid::Extensions::DateTime::ClassMethods
Methods included from Mongoid::Extensions::BigDecimal::ClassMethods
Instance Method Details
#check_if_transactions_might_be_available!(client) ⇒ Object
This method raises an error if the cluster the client is connected to does not support transactions in any case. At the moment this is the case of the standalone topology.
Please note that if this method did not raise, it does not guarantee that transactions are available for the cluster.
15 16 17 18 19 |
# File 'lib/mongoid/railties/console_sandbox.rb', line 15 def check_if_transactions_might_be_available!(client) if client.cluster.single? raise Mongoid::Errors::TransactionsNotSupported end end |
#start_sandbox ⇒ Object
Prepares console sandbox mode. This method should be called when a user starts rails console with ‘–sandbox’ flag.
35 36 37 38 39 40 |
# File 'lib/mongoid/railties/console_sandbox.rb', line 35 def start_sandbox Mongoid.persistence_context.client.tap do |client| check_if_transactions_might_be_available!(client) start_sandbox_transaction(client) end end |
#start_sandbox_transaction(client) ⇒ Object
Starts a transaction that should include all the operations inside the sandboxed console session. This transaction should not be ever committed. When a user end the console session, the client will disconnect, and the transaction will be automatically aborted therefore.
27 28 29 30 31 |
# File 'lib/mongoid/railties/console_sandbox.rb', line 27 def start_sandbox_transaction(client) session = client.start_session ::Mongoid::Threaded.set_session(session, client: client) session.start_transaction end |