Class: AfterCommitEverywhere::Wrap
- Inherits:
-
Object
- Object
- AfterCommitEverywhere::Wrap
- 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
-
#add_to_transaction ⇒ Object
Required for transaction(requires_new: true).
-
#before_committed! ⇒ Object
rubocop: enable Naming/PredicateName.
- #committed!(should_run_callbacks: true) ⇒ Object
-
#has_transactional_callbacks? ⇒ Boolean
rubocop: disable Naming/PredicateName.
-
#initialize(connection: ActiveRecord::Base.connection, **handlers) ⇒ Wrap
constructor
A new instance of Wrap.
- #rolledback! ⇒ Object
- #trigger_transactional_callbacks? ⇒ Boolean
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_transaction ⇒ Object
Required for transaction(requires_new: true)
37 38 39 |
# File 'lib/after_commit_everywhere/wrap.rb', line 37 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!(should_run_callbacks: true) ⇒ Object
26 27 28 29 30 |
# File 'lib/after_commit_everywhere/wrap.rb', line 26 def committed!(should_run_callbacks: true) if should_run_callbacks @handlers[:after_commit]&.call end end |
#has_transactional_callbacks? ⇒ Boolean
rubocop: disable Naming/PredicateName
13 14 15 |
# File 'lib/after_commit_everywhere/wrap.rb', line 13 def has_transactional_callbacks? true end |
#rolledback! ⇒ Object
32 33 34 |
# File 'lib/after_commit_everywhere/wrap.rb', line 32 def rolledback!(*) @handlers[:after_rollback]&.call end |
#trigger_transactional_callbacks? ⇒ Boolean
22 23 24 |
# File 'lib/after_commit_everywhere/wrap.rb', line 22 def trigger_transactional_callbacks? true end |