Module: ARAfterTransaction::ClassMethods

Defined in:
lib/ar_after_transaction.rb

Instance Method Summary collapse

Instance Method Details

#after_transaction(&block) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/ar_after_transaction.rb', line 26

def after_transaction(&block)
  if transactions_open?
    connection.after_transaction_callbacks ||= []
    connection.after_transaction_callbacks << block
  else
    yield
  end
end

#normally_open_transactionsObject



35
36
37
# File 'lib/ar_after_transaction.rb', line 35

def normally_open_transactions
  @@normally_open_transactions ||= 0
end

#normally_open_transactions=(value) ⇒ Object



39
40
41
# File 'lib/ar_after_transaction.rb', line 39

def normally_open_transactions=(value)
  @@normally_open_transactions = value
end

#transaction(*args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ar_after_transaction.rb', line 6

def transaction(*args)
  clean = true
  super(*args) do
    begin
      yield
    rescue ActiveRecord::Rollback
      clean = false
      raise
    end
  end
rescue Exception
  clean = false
  raise
ensure
  unless transactions_open?
    callbacks = delete_after_transaction_callbacks
    callbacks.each(&:call) if clean
  end
end