Module: Rollwire::DatabaseStatementsPatch

Defined in:
lib/rollwire/patches/database_statements.rb

Instance Method Summary collapse

Instance Method Details

#transaction(**options, &block) ⇒ Object



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
# File 'lib/rollwire/patches/database_statements.rb', line 5

def transaction(**options, &block)
  joined = Rollwire.enabled? &&
           open_transactions.positive? &&
           !options[:requires_new] &&
           current_transaction.joinable?

  return super(**options, &block) unless joined && block

  pushed = false
  begin
    inner_location = Rollwire.caller_location
    WriteCounter.push_frame(self)
    pushed = true
  rescue StandardError => e
    Rollwire.warn_internal_error(e)
    return super(**options, &block)
  end

  super(**options) do |*arguments|
    block.call(*arguments)
  rescue ActiveRecord::Rollback => e
    report_ignored_rollback(inner_location)
    raise e
  end
ensure
  safely_pop_write_frame if pushed
end