Sha256: 65cc6735dfc8081f73670f870e3115987c413f4c5203e429cb7e69f8721bc4bb
Contents?: true
Size: 997 Bytes
Versions: 27
Compression:
Stored size: 997 Bytes
Contents
module Arql::Commands module Sandbox class << self attr_accessor :enabled @sandbox_callback = proc do begin_transaction(joinable: false) end def enter ActiveRecord::ConnectionAdapters::AbstractAdapter.set_callback(:checkout, :after, &@sandbox_callback) ActiveRecord::Base.connection.begin_transaction(joinable: false) @enabled = true end def quit ActiveRecord::ConnectionAdapters::AbstractAdapter.skip_callback(:checkout, :after, &@sandbox_callback) @enabled = false puts "begin_transaction callbacks removed." puts "You still have open %d transactions open, don't forget commit or rollback them." % ActiveRecord::Base.connection.open_transactions if ActiveRecord::Base.connection.open_transactions > 0 end end Pry.commands.block_command 'sandbox-enter' do Sandbox.enter end Pry.commands.block_command 'sandbox-quit' do Sandbox.quit end end end
Version data entries
27 entries across 27 versions & 1 rubygems