Class: ActiveRecord::ConnectionAdapters::TransactionState

Inherits:
Object
  • Object
show all
Defined in:
activerecord/lib/active_record/connection_adapters/abstract/transaction.rb

Constant Summary collapse

VALID_STATES =
Set.new([:committed, :rolledback, nil])

Instance Method Summary collapse

Constructor Details

#initialize(state = nil) ⇒ TransactionState

Returns a new instance of TransactionState.


6
7
8
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 6

def initialize(state = nil)
  @state = state
end

Instance Method Details

#committed?Boolean

Returns:

  • (Boolean)

14
15
16
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 14

def committed?
  @state == :committed
end

#completed?Boolean

Returns:

  • (Boolean)

22
23
24
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 22

def completed?
  committed? || rolledback?
end

#finalized?Boolean

Returns:

  • (Boolean)

10
11
12
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 10

def finalized?
  @state
end

#rolledback?Boolean

Returns:

  • (Boolean)

18
19
20
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 18

def rolledback?
  @state == :rolledback
end

#set_state(state) ⇒ Object


26
27
28
29
30
31
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 26

def set_state(state)
  unless VALID_STATES.include?(state)
    raise ArgumentError, "Invalid transaction state: #{state}"
  end
  @state = state
end