Class: FlowEngine::DSL::FlowBuilder

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

Overview

Builds a FlowEngine::Definition from the declarative DSL used in FlowEngine.define. Provides #start and #step; each step block is evaluated by StepBuilder with RuleHelpers.

Instance Method Summary collapse

Methods included from RuleHelpers

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

Constructor Details

#initialize ⇒ FlowBuilder

Returns a new instance of FlowBuilder.



10
11
12
13
14
# File 'lib/flowengine/dsl/flow_builder.rb', line 10

def initialize
  @start_step_id = nil
  @nodes = {}
  @introduction = nil
end

Instance Method Details

#build ⇒ Definition

Produces the frozen FlowEngine::Definition from the accumulated start and steps.

Returns:

Raises:

  • (DefinitionError) —

    if start was not set or no steps were defined



47
48
49
50
51
52
# File 'lib/flowengine/dsl/flow_builder.rb', line 47

def build
  raise ::FlowEngine::Errors::DefinitionError, "No start step defined" if @start_step_id.nil?
  raise ::FlowEngine::Errors::DefinitionError, "No steps defined" if @nodes.empty?

  Definition.new(start_step_id: @start_step_id, nodes: @nodes, introduction: @introduction)
end

#introduction(label:, placeholder: "", maxlength: nil) ⇒ Object

Configures an introduction step that collects free-form text before the flow begins. The LLM parses this text to pre-fill answers for subsequent steps.

Parameters:

  • label (String) —

    text shown above the input field

  • placeholder (String) (defaults to: "") —

    text shown inside the empty text area

  • maxlength (Integer, nil) (defaults to: nil) —

    maximum character count for the text (nil = unlimited)



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

def introduction(label:, placeholder: "", maxlength: nil)
  @introduction = Introduction.new(label: label, placeholder: placeholder, maxlength: maxlength)
end

#start(step_id) ⇒ Object

Sets the entry step id for the flow.

Parameters:

  • step_id (Symbol) —

    id of the first step



19
20
21
# File 'lib/flowengine/dsl/flow_builder.rb', line 19

def start(step_id)
  @start_step_id = step_id
end

#step(id) { ... } ⇒ Object

Defines one step by id; the block is evaluated in a StepBuilder context.

Parameters:

  • id (Symbol) —

    step id

Yields:

  • block evaluated in StepBuilder (type, question, options, transition, etc.)



37
38
39
40
41
# File 'lib/flowengine/dsl/flow_builder.rb', line 37

def step(id, &)
  builder = StepBuilder.new
  builder.instance_eval(&)
  @nodes[id] = builder.build(id)
end