Sha256: 1a826a27f83c5b63bb36b3474185d0d33c57635aec7e15d5e8262f3364731706
Contents?: true
Size: 988 Bytes
Versions: 1
Compression:
Stored size: 988 Bytes
Contents
# frozen_string_literal: true module AfterCommitEverywhere # ActiveRecord model-like class to fake ActiveRecord to make it believe # that it calls transactional callbacks on real model objects. class Wrap def initialize(connection: ActiveRecord::Base.connection, **handlers) @connection = connection @handlers = handlers end # rubocop: disable Naming/PredicateName def has_transactional_callbacks? true end # rubocop: enable Naming/PredicateName def before_committed!(*) @handlers[:before_commit]&.call end def trigger_transactional_callbacks? true end def committed!(should_run_callbacks: true) if should_run_callbacks @handlers[:after_commit]&.call end end def rolledback!(*) @handlers[:after_rollback]&.call end # Required for +transaction(requires_new: true)+ def add_to_transaction(*) @connection.add_transaction_record(self) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
after_commit_everywhere-1.5.0 | lib/after_commit_everywhere/wrap.rb |