Module: Foobara::Persistence::EntityBase::Transaction::Concerns::TransactionTracking::ClassMethods
- Defined in:
- foobara-0.0.110/projects/persistence/src/entity_base/transaction/concerns/transaction_tracking.rb
Instance Method Summary collapse
- #install! ⇒ Object
- #open_transaction_for(record) ⇒ Object
- #open_transactions ⇒ Object
- #reset_all ⇒ Object
Instance Method Details
#install! ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'foobara-0.0.110/projects/persistence/src/entity_base/transaction/concerns/transaction_tracking.rb', line 10 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 |
#open_transaction_for(record) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'foobara-0.0.110/projects/persistence/src/entity_base/transaction/concerns/transaction_tracking.rb', line 31 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 |
#open_transactions ⇒ Object
27 28 29 |
# File 'foobara-0.0.110/projects/persistence/src/entity_base/transaction/concerns/transaction_tracking.rb', line 27 def open_transactions @open_transactions ||= Set.new end |
#reset_all ⇒ Object
23 24 25 |
# File 'foobara-0.0.110/projects/persistence/src/entity_base/transaction/concerns/transaction_tracking.rb', line 23 def reset_all @open_transactions = nil end |