Class: FlowEngine::DSL::StepBuilder

Inherits:
Object
  • Object
show all
Includes:
RuleHelpers
Defined in:
lib/flowengine/dsl/step_builder.rb

Overview

Builds a single Node from step DSL (type, question, options, transitions, visibility). Used by FlowBuilder#step; includes RuleHelpers for transition/visibility conditions.

Instance Method Summary collapse

Methods included from RuleHelpers

#all, #any, #contains, #equals, #greater_than, #less_than, #not_empty

Constructor Details

#initialize ⇒ StepBuilder

Returns a new instance of StepBuilder.



10
11
12
13
14
15
16
17
18
19
# File 'lib/flowengine/dsl/step_builder.rb', line 10

def initialize
  @type = nil
  @question = nil
  @options = nil
  @fields = nil
  @transitions = []
  @visibility_rule = nil
  @decorations = nil
  @max_clarifications = 0
end

Instance Method Details

#build(id) ⇒ Node

Builds the Node for the given step id from accumulated attributes.

Parameters:

  • id (Symbol) —

    step id

Returns:



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/flowengine/dsl/step_builder.rb', line 77

def build(id)
  Node.new(
    id: id,
    type: @type,
    question: @question,
    options: @options,
    fields: @fields,
    transitions: @transitions,
    visibility_rule: @visibility_rule,
    decorations: @decorations,
    max_clarifications: @max_clarifications
  )
end

#decorations(decorations) ⇒ Object

Optional UI decorations (opaque to the engine).

Parameters:

  • decorations (Object)


47
48
49
# File 'lib/flowengine/dsl/step_builder.rb', line 47

def decorations(decorations)
  @decorations = decorations
end

#fields(list) ⇒ Object

Sets the list of field names for matrix-style steps (e.g. number_matrix).

Parameters:

  • list (Array)


41
42
43
# File 'lib/flowengine/dsl/step_builder.rb', line 41

def fields(list)
  @fields = list
end

#max_clarifications(count) ⇒ Object

Sets the maximum number of clarification rounds for an :ai_intake step.

Parameters:

  • count (Integer) —

    max follow-up rounds (0 = one-shot, no clarifications)



69
70
71
# File 'lib/flowengine/dsl/step_builder.rb', line 69

def max_clarifications(count)
  @max_clarifications = count
end

#options(list) ⇒ Object

Sets the list of options for multi-select or choice steps.

Parameters:

  • list (Array)


35
36
37
# File 'lib/flowengine/dsl/step_builder.rb', line 35

def options(list)
  @options = list
end

#question(text) ⇒ Object

Sets the prompt/label for the step.

Parameters:

  • text (String)


29
30
31
# File 'lib/flowengine/dsl/step_builder.rb', line 29

def question(text)
  @question = text
end

#transition(to:, if_rule: nil) ⇒ Object

Adds a conditional transition to another step. First matching transition wins.

Parameters:

  • to (Symbol) —

    target step id

  • if_rule (Rules::Base, nil) (defaults to: nil) —

    condition (nil = unconditional)



55
56
57
# File 'lib/flowengine/dsl/step_builder.rb', line 55

def transition(to:, if_rule: nil)
  @transitions << Transition.new(target: to, rule: if_rule)
end

#type(value) ⇒ Object

Sets the step/input type (e.g. :multi_select, :number_matrix).

Parameters:

  • value (Symbol)


23
24
25
# File 'lib/flowengine/dsl/step_builder.rb', line 23

def type(value)
  @type = value
end

#visible_if(rule) ⇒ Object

Sets the visibility rule for this step (DAG mode: step shown only when rule is true).

Parameters:



62
63
64
# File 'lib/flowengine/dsl/step_builder.rb', line 62

def visible_if(rule)
  @visibility_rule = rule
end