Class: LittleGhost::Graph::State

Inherits:
Object
  • Object
show all
Defined in:
lib/little_ghost/graph.rb

Overview

Read-only routing data passed to conditions and input mappers.

results contains every completed node result. incoming_results contains only the immediate predecessors supplying the current node. previous and #previous_result are present for a single predecessor; predecessors preserves declaration order for fan-in execution.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input:, history:, context:, step:, current:, previous:, results:, predecessors: [], incoming_results: {}, error: nil) ⇒ State

Returns a new instance of State.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/little_ghost/graph.rb', line 85

def initialize(input:, history:, context:, step:, current:, previous:, results:,
  predecessors: [], incoming_results: {}, error: nil) # :nodoc:
  @input = input
  @history = history
  @context = context
  @step = step
  @current = current
  @previous = previous
  @predecessors = Array(predecessors).map(&:to_sym).freeze
  @results = results.dup.freeze
  @incoming_results = incoming_results.dup.freeze
  @error = error
  freeze
end

Instance Attribute Details

#contextObject (readonly)

A frozen copy of application context available to the condition or mapper.



69
70
71
# File 'lib/little_ghost/graph.rb', line 69

def context
  @context
end

#currentObject (readonly)

The source node for a condition, or destination node for an input mapper.



73
74
75
# File 'lib/little_ghost/graph.rb', line 73

def current
  @current
end

#errorObject (readonly)

A frozen copy of the routed exception available to an error-edge mapper.



83
84
85
# File 'lib/little_ghost/graph.rb', line 83

def error
  @error
end

#historyObject (readonly)

A frozen copy of caller history available to the condition or mapper.



67
68
69
# File 'lib/little_ghost/graph.rb', line 67

def history
  @history
end

#incoming_resultsObject (readonly)

Frozen copies of immediate predecessor RunResults keyed by node name.



81
82
83
# File 'lib/little_ghost/graph.rb', line 81

def incoming_results
  @incoming_results
end

#inputObject (readonly)

A copied Message containing the original request.



65
66
67
# File 'lib/little_ghost/graph.rb', line 65

def input
  @input
end

#predecessorsObject (readonly)

The immediate predecessor names in declaration order.



77
78
79
# File 'lib/little_ghost/graph.rb', line 77

def predecessors
  @predecessors
end

#previousObject (readonly)

The predecessor name when exactly one result supplies the current node.



75
76
77
# File 'lib/little_ghost/graph.rb', line 75

def previous
  @previous
end

#resultsObject (readonly)

Frozen copies of completed RunResults keyed by node name.



79
80
81
# File 'lib/little_ghost/graph.rb', line 79

def results
  @results
end

#stepObject (readonly)

The one-based execution count assigned to the current node.



71
72
73
# File 'lib/little_ghost/graph.rb', line 71

def step
  @step
end

Instance Method Details

#previous_resultObject

Returns the immediately preceding result when present.



103
# File 'lib/little_ghost/graph.rb', line 103

def previous_result = previous && result(previous)

#result(node_name) ⇒ Object

Returns a completed result by node name.



101
102
# File 'lib/little_ghost/graph.rb', line 101

def result(node_name) = results[node_name.to_sym]
# Returns the immediately preceding result when present.