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

Version Path
arql-0.3.31 lib/arql/commands/sandbox.rb
arql-0.3.30 lib/arql/commands/sandbox.rb
arql-0.3.29 lib/arql/commands/sandbox.rb
arql-0.3.28 lib/arql/commands/sandbox.rb
arql-0.3.27 lib/arql/commands/sandbox.rb
arql-0.3.26 lib/arql/commands/sandbox.rb
arql-0.3.25 lib/arql/commands/sandbox.rb
arql-0.3.24 lib/arql/commands/sandbox.rb
arql-0.3.23 lib/arql/commands/sandbox.rb
arql-0.3.22 lib/arql/commands/sandbox.rb
arql-0.3.21 lib/arql/commands/sandbox.rb
arql-0.3.20 lib/arql/commands/sandbox.rb
arql-0.3.19 lib/arql/commands/sandbox.rb
arql-0.3.18 lib/arql/commands/sandbox.rb
arql-0.3.17 lib/arql/commands/sandbox.rb
arql-0.3.16 lib/arql/commands/sandbox.rb
arql-0.3.15 lib/arql/commands/sandbox.rb
arql-0.3.14 lib/arql/commands/sandbox.rb
arql-0.3.13 lib/arql/commands/sandbox.rb
arql-0.3.12 lib/arql/commands/sandbox.rb