Class: Effective::AfterCommit
- Inherits:
-
Object
- Object
- Effective::AfterCommit
- Defined in:
- app/models/effective/after_commit.rb
Class Method Summary collapse
Instance Method Summary collapse
- #before_committed! ⇒ Object
- #committed!(args) ⇒ Object
- #has_transactional_callbacks? ⇒ Boolean
-
#initialize(**handlers) ⇒ AfterCommit
constructor
A new instance of AfterCommit.
- #rolledback! ⇒ Object
- #trigger_transactional_callbacks? ⇒ Boolean
Constructor Details
#initialize(**handlers) ⇒ AfterCommit
Returns a new instance of AfterCommit.
4 5 6 |
# File 'app/models/effective/after_commit.rb', line 4 def initialize(**handlers) @handlers = handlers end |
Class Method Details
.register_callback(connection:, name:, callback:) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/effective/after_commit.rb', line 28 def self.register_callback(connection:, name:, callback:) raise ArgumentError, "#{name} expected a block" unless callback in_transaction = (connection.transaction_open? && connection.current_transaction.joinable?) # Execute immediately when outside transaction return callback.call unless in_transaction after_commit = Effective::AfterCommit.new("#{name}": callback) connection.add_transaction_record(after_commit) end |
Instance Method Details
#before_committed! ⇒ Object
16 17 18 |
# File 'app/models/effective/after_commit.rb', line 16 def before_committed!(*) @handlers[:before_commit]&.call end |
#committed!(args) ⇒ Object
20 21 22 |
# File 'app/models/effective/after_commit.rb', line 20 def committed!(args) @handlers[:after_commit]&.call end |
#has_transactional_callbacks? ⇒ Boolean
8 9 10 |
# File 'app/models/effective/after_commit.rb', line 8 def has_transactional_callbacks? true end |
#rolledback! ⇒ Object
24 25 26 |
# File 'app/models/effective/after_commit.rb', line 24 def rolledback!(*) @handlers[:after_rollback]&.call end |
#trigger_transactional_callbacks? ⇒ Boolean
12 13 14 |
# File 'app/models/effective/after_commit.rb', line 12 def trigger_transactional_callbacks? true end |