Class: FlowEngine::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/flowengine/definition.rb

Overview

Immutable, versionable flow graph: maps step ids to Node objects and defines the entry point. Built by FlowEngine::DSL::FlowBuilder; consumed by Engine for navigation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_step_id:, nodes:, introduction: nil) ⇒ Definition

Returns a new instance of Definition.

Parameters:

  • start_step_id (Symbol) —

    id of the initial step

  • nodes (Hash<Symbol, Node>) —

    all steps keyed by id

  • introduction (Introduction, nil) (defaults to: nil) —

    optional introduction config (label + placeholder)

Raises:

  • (DefinitionError) —

    if start_step_id is not present in nodes



16
17
18
19
20
21
22
# File 'lib/flowengine/definition.rb', line 16

def initialize(start_step_id:, nodes:, introduction: nil)
  @start_step_id = start_step_id
  @steps = nodes.freeze
  @introduction = introduction
  validate!
  freeze
end

Instance Attribute Details

#introduction ⇒ Object (readonly)

Returns the value of attribute introduction.



10
11
12
# File 'lib/flowengine/definition.rb', line 10

def introduction
  @introduction
end

#start_step_id ⇒ Symbol (readonly)

id of the first step in the flow

Returns:

  • (Symbol) —

    the current value of start_step_id



9
10
11
# File 'lib/flowengine/definition.rb', line 9

def start_step_id
  @start_step_id
end

#steps ⇒ Hash<Symbol, Node> (readonly)

frozen map of step id => node (read-only)

Returns:

  • (Hash<Symbol, Node>) —

    the current value of steps



9
10
11
# File 'lib/flowengine/definition.rb', line 9

def steps
  @steps
end

Instance Method Details

#start_step ⇒ Node

Returns the node for the start step.

Returns:

  • (Node) —

    the node for the start step



25
26
27
# File 'lib/flowengine/definition.rb', line 25

def start_step
  step(start_step_id)
end

#step(id) ⇒ Node

Returns the node for that step.

Parameters:

  • id (Symbol) —

    step id

Returns:

  • (Node) —

    the node for that step

Raises:

  • (UnknownStepError) —

    if id is not in steps



32
33
34
# File 'lib/flowengine/definition.rb', line 32

def step(id)
  steps.fetch(id) { raise Errors::UnknownStepError, "Unknown step: #{id.inspect}" }
end

#step_ids ⇒ Array<Symbol>

Returns all step ids in the definition.

Returns:

  • (Array<Symbol>) —

    all step ids in the definition



37
38
39
# File 'lib/flowengine/definition.rb', line 37

def step_ids
  steps.keys
end