Sha256: 30afcf9992219067871d1bdf4c28d5b6311509fa0f4b5e43a54a72b3809c8403

Contents?: true

Size: 941 Bytes

Versions: 9

Compression:

Stored size: 941 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)
        Arql::App.instance.definitions.each do |_, definition|
          definition.connection.begin_transaction(joinable: false)
        end
        @enabled = true
      end

      def quit
        ActiveRecord::ConnectionAdapters::AbstractAdapter.skip_callback(:checkout, :after, &@sandbox_callback)
        Arql::App.instance.definitions.each do |_, definition|
          definition.connection.rollback_transaction
        end
        @enabled = false
      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

9 entries across 9 versions & 1 rubygems

Version Path
arql-0.4.11 lib/arql/commands/sandbox.rb
arql-0.4.10 lib/arql/commands/sandbox.rb
arql-0.4.8 lib/arql/commands/sandbox.rb
arql-0.4.7 lib/arql/commands/sandbox.rb
arql-0.4.6 lib/arql/commands/sandbox.rb
arql-0.4.3 lib/arql/commands/sandbox.rb
arql-0.4.2 lib/arql/commands/sandbox.rb
arql-0.4.1 lib/arql/commands/sandbox.rb
arql-0.4.0 lib/arql/commands/sandbox.rb