Class: ActiveRecordCompose::TransactionSupport::ActiveTransaction

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record_compose/transaction_support/active_transaction.rb

Overview

In older versions, the ActiveRecord::Transaction object is not passed to the block argument of #transaction. So instead, we define a transaction object that can be evaluated equivalently. This follow-up will no longer be necessary when support for Rails 7.1 is dropped.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transaction) ⇒ ActiveTransaction

Returns a new instance of ActiveTransaction.



13
14
15
# File 'lib/active_record_compose/transaction_support/active_transaction.rb', line 13

def initialize(transaction)
  @real_transaction = transaction
end

Instance Attribute Details

#real_transactionvoid (readonly)

Returns the value of attribute real_transaction.



17
18
19
# File 'lib/active_record_compose/transaction_support/active_transaction.rb', line 17

def real_transaction
  @real_transaction
end

Instance Method Details

#==(other) ⇒ void



23
24
25
26
27
28
# File 'lib/active_record_compose/transaction_support/active_transaction.rb', line 23

def ==(other)
  return true if equal?(other)
  return false unless self.class == other.class

  real_transaction == other.real_transaction
end

#closed?Boolean

Returns:

  • (Boolean)


21
# File 'lib/active_record_compose/transaction_support/active_transaction.rb', line 21

def closed? = real_transaction&.state&.completed?

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
# File 'lib/active_record_compose/transaction_support/active_transaction.rb', line 30

def eql?(other)
  return true if equal?(other)
  return false unless self.class == other.class

  real_transaction.eql?(other.real_transaction)
end

#hashvoid



37
# File 'lib/active_record_compose/transaction_support/active_transaction.rb', line 37

def hash = real_transaction.hash

#open?Boolean

Returns:

  • (Boolean)


19
# File 'lib/active_record_compose/transaction_support/active_transaction.rb', line 19

def open? = !closed?