Sha256: d717566d5108c623c1efb5775fb373b3bc4a8f2be7344004647bb7e9dba99aa4

Contents?: true

Size: 860 Bytes

Versions: 4

Compression:

Stored size: 860 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 committed!(*)
      @handlers[:after_commit]&.call
    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

4 entries across 4 versions & 1 rubygems

Version Path
after_commit_everywhere-0.1.3 lib/after_commit_everywhere/wrap.rb
after_commit_everywhere-0.1.2 lib/after_commit_everywhere/wrap.rb
after_commit_everywhere-0.1.1 lib/after_commit_everywhere/wrap.rb
after_commit_everywhere-0.1.0 lib/after_commit_everywhere/wrap.rb