Class: AfterCommitEverywhere::Wrap

Inherits:
Object
  • Object
show all
Defined in:
lib/after_commit_everywhere/wrap.rb

Overview

ActiveRecord model-like class to fake ActiveRecord to make it believe that it calls transactional callbacks on real model objects.

Instance Method Summary collapse

Constructor Details

#initialize(connection: ActiveRecord::Base.connection, **handlers) ⇒ Wrap

Returns a new instance of Wrap.



7
8
9
10
# File 'lib/after_commit_everywhere/wrap.rb', line 7

def initialize(connection: ActiveRecord::Base.connection, **handlers)
  @connection = connection
  @handlers = handlers
end

Instance Method Details

#add_to_transactionObject

Required for transaction(requires_new: true)



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

def add_to_transaction(*)
  @connection.add_transaction_record(self)
end

#before_committed!Object

rubocop: enable Naming/PredicateName



18
19
20
# File 'lib/after_commit_everywhere/wrap.rb', line 18

def before_committed!(*)
  @handlers[:before_commit]&.call
end

#committed!Object



26
27
28
# File 'lib/after_commit_everywhere/wrap.rb', line 26

def committed!(*)
  @handlers[:after_commit]&.call
end

#has_transactional_callbacks?Boolean

rubocop: disable Naming/PredicateName

Returns:

  • (Boolean)


13
14
15
# File 'lib/after_commit_everywhere/wrap.rb', line 13

def has_transactional_callbacks?
  true
end

#rolledback!Object



30
31
32
# File 'lib/after_commit_everywhere/wrap.rb', line 30

def rolledback!(*)
  @handlers[:after_rollback]&.call
end

#trigger_transactional_callbacks?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/after_commit_everywhere/wrap.rb', line 22

def trigger_transactional_callbacks?
  true
end