Class: ActiveRecord::ConnectionAdapters::TransactionState

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

Overview

Active Record Connection Adapters Transaction State

Instance Method Summary collapse

Constructor Details

#initialize(state = nil) ⇒ TransactionState

Returns a new instance of TransactionState.



7
8
9
10
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 7

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

Instance Method Details

#add_child(state) ⇒ Object



12
13
14
15
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 12

def add_child(state)
  @children ||= []
  @children << state
end

#commit!Object



64
65
66
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 64

def commit!
  @state = :committed
end

#committed?Boolean

Returns:

  • (Boolean)


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

def committed?
  @state == :committed || @state == :fully_committed
end

#completed?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 45

def completed?
  committed? || rolledback?
end

#finalized?Boolean

Returns:

  • (Boolean)


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

def finalized?
  @state
end

#full_commit!Object



68
69
70
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 68

def full_commit!
  @state = :fully_committed
end

#full_rollback!Object



54
55
56
57
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 54

def full_rollback!
  @children&.each { |c| c.rollback! }
  @state = :fully_rolledback
end

#fully_committed?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 25

def fully_committed?
  @state == :fully_committed
end

#fully_completed?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 41

def fully_completed?
  completed?
end

#fully_rolledback?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 33

def fully_rolledback?
  @state == :fully_rolledback
end

#invalidate!Object



59
60
61
62
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 59

def invalidate!
  @children&.each { |c| c.invalidate! }
  @state = :invalidated
end

#invalidated?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 37

def invalidated?
  @state == :invalidated
end

#nullify!Object



72
73
74
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 72

def nullify!
  @state = nil
end

#rollback!Object



49
50
51
52
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 49

def rollback!
  @children&.each { |c| c.rollback! }
  @state = :rolledback
end

#rolledback?Boolean

Returns:

  • (Boolean)


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

def rolledback?
  @state == :rolledback || @state == :fully_rolledback
end