Sha256: 9f9a191ec448dc7b84aeb6f924ca21dda4bc617254ff4a9672241e1abac096c3
Contents?: true
Size: 1.64 KB
Versions: 26
Compression:
Stored size: 1.64 KB
Contents
module Foobara module Persistence class EntityBase class Transaction module Concerns module TransactionTracking include Concern module ClassMethods def install! Transaction::StateMachine.register_transition_callback(:after, transition: :open) do |state_machine:, **| transaction = state_machine.owner Transaction.open_transactions << transaction end Transaction::StateMachine.register_transition_callback(:after, to: :closed) do |state_machine:, **| transaction = state_machine.owner Transaction.open_transactions.delete(transaction) end end def reset_all @open_transactions = nil end def open_transactions @open_transactions ||= Set.new end def open_transaction_for(record) # let's check the current_transaction first since that usually will match tx = Persistence.current_transaction(record) if tx&.tracking?(record) return tx else entity_base = record.class.entity_base tx = open_transactions.find do |transaction| transaction.entity_base == entity_base && transaction.tracking?(record) end end tx end end end end end end end end
Version data entries
26 entries across 26 versions & 1 rubygems