Class: FlowEngine::DSL::FlowBuilder
- Inherits:
-
Object
- Object
- FlowEngine::DSL::FlowBuilder
- 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
-
#build ⇒ Definition
Produces the frozen FlowEngine::Definition from the accumulated start and steps.
-
#initialize ⇒ FlowBuilder
constructor
A new instance of FlowBuilder.
-
#introduction(label:, placeholder: "", maxlength: nil) ⇒ Object
Configures an introduction step that collects free-form text before the flow begins.
-
#start(step_id) ⇒ Object
Sets the entry step id for the flow.
-
#step(id) { ... } ⇒ Object
Defines one step by id; the block is evaluated in a StepBuilder context.
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.
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.
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.
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.
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 |