Class: Statecraft::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/statecraft/pipeline.rb

Overview

Executes one transition through the protocol pipeline:

persisted? -> metadata normalize+freeze -> edge resolution ->
dirty check (lock only) -> transaction(requires_new: true) [
lock+reload -> re-resolve edge from fresh state -> guards ->
before_transition -> CAS UPDATE -> log INSERT (insert path) ->
after_transition
] -> after_commit registration on the outermost real commit

The CAS statement and the log insert run against base_class; the log row is written via the insert path, past the log model's validations and callbacks — guards and machine callbacks are the single channel of truth.

Defined Under Namespace

Modules: Surface Classes: Frame, Transition

Constant Summary collapse

STACK_KEY =
:statecraft_transition_stack
MAX_CHAIN_DEPTH =
16

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ Pipeline

Returns a new instance of Pipeline.



61
62
63
64
65
66
# File 'lib/statecraft/pipeline.rb', line 61

def initialize(record)
  @record = record
  @configuration = record.class.statecraft_mounting
  @graph = @configuration.machine_class.finalize!
  @machine_instance = @configuration.machine_class.new
end

Class Method Details

.transition_stack ⇒ Object



31
32
33
# File 'lib/statecraft/pipeline.rb', line 31

def self.transition_stack
  ActiveSupport::IsolatedExecutionState[STACK_KEY] ||= []
end

Instance Method Details

#direct(to_state, metadata:, bypass_events:) ⇒ Object



68
69
70
71
72
73
# File 'lib/statecraft/pipeline.rb', line 68

def direct(to_state, metadata:, bypass_events:)
  run() do |current_state|
    edge = resolve_direct_edge(current_state, to_state.to_sym, bypass_events)
    [edge, nil, bypass_events]
  end
end

#fire(event_name, metadata:) ⇒ Object



75
76
77
78
79
80
# File 'lib/statecraft/pipeline.rb', line 75

def fire(event_name, metadata:)
  run() do |current_state|
    edge = resolve_event_edge(current_state, event_name.to_sym)
    [edge, event_name.to_sym, false]
  end
end