Top Level Namespace
Defined Under Namespace
Modules: ApplicationCable, ApplicationHelper, Blog, CommentsHelper, Mongoid, MongoidTest, MongoidTestConfig, MongoidTestInit, PostsHelper, Rails, RailsApi Classes: ApplicationController, ApplicationJob, ApplicationMailer, ApplicationSystemTestCase, Comment, CommentTest, CommentsController, Post, PostTest, PostsController
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.
-
#standard_dependencies ⇒ Object
rubocop:todo all.
-
#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.
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.
16 17 18 19 20 |
# File 'lib/mongoid/railties/console_sandbox.rb', line 16 def check_if_transactions_might_be_available!(client) if client.cluster.single? raise Mongoid::Errors::TransactionsNotSupported end end |
#standard_dependencies ⇒ Object
rubocop:todo all
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'gemfiles/standard.rb', line 2 def standard_dependencies gem 'rake' group :development do gem 'yard' platform :mri do # Debugger for VSCode. if !ENV['CI'] && !ENV['DOCKER'] && RUBY_VERSION < '3.0' gem 'debase' gem 'ruby-debug-ide' end end # Evergreen configuration generation gem 'erubi' gem 'tilt' gem 'solargraph', platform: :mri end group :development, :test do gem 'rspec', '~> 3.12' gem 'rubocop', '~> 1.45.1' gem 'rubocop-performance', '~> 1.16.0' gem 'rubocop-rake', '~> 0.6.0' gem 'rubocop-rspec', '~> 2.18.1' platform :mri do gem 'byebug' end platform :jruby do gem 'ruby-debug' end end group :test do gem 'activejob' gem 'timecop' gem 'rspec-retry' gem 'benchmark-ips' gem 'fuubar' gem 'rfc' gem 'childprocess' platform :mri do gem 'timeout-interrupt' end end if ENV['FLE'] == 'helper' gem 'libmongocrypt-helper', '~> 1.8.0' end end |
#start_sandbox ⇒ Object
Prepares console sandbox mode. This method should be called when a user starts rails console with ‘–sandbox’ flag.
36 37 38 39 40 41 |
# File 'lib/mongoid/railties/console_sandbox.rb', line 36 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.
28 29 30 31 32 |
# File 'lib/mongoid/railties/console_sandbox.rb', line 28 def start_sandbox_transaction(client) session = client.start_session ::Mongoid::Threaded.set_session(session, client: client) session.start_transaction end |