Class: Inquirex::DSL::FlowBuilder

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

Overview

Builds a Definition from the declarative DSL block used in Inquirex.define. Provides start, meta, and all verb methods (ask, say, header, btw, warning, confirm).

Instance Method Summary collapse

Methods included from RuleHelpers

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

Constructor Details

#initialize(id: nil, version: "1.0.0") ⇒ FlowBuilder

Returns a new instance of FlowBuilder.

Parameters:

  • id (String, nil) (defaults to: nil)

    optional flow identifier

  • version (String) (defaults to: "1.0.0")

    semver



12
13
14
15
16
17
18
# File 'lib/inquirex/dsl/flow_builder.rb', line 12

def initialize(id: nil, version: "1.0.0")
  @flow_id = id
  @flow_version = version
  @start_step_id = nil
  @nodes = {}
  @meta = {}
end

Instance Method Details

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

Defines a question step that collects typed input from the user.

Parameters:

  • id (Symbol)

    step id

Yields:

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



42
43
44
# File 'lib/inquirex/dsl/flow_builder.rb', line 42

def ask(id, &)
  add_step(id, :ask, &)
end

#btw(id) ⇒ Object

Defines an admonition or sidebar note step (no input collected).

Parameters:

  • id (Symbol)

    step id



63
64
65
# File 'lib/inquirex/dsl/flow_builder.rb', line 63

def btw(id, &)
  add_step(id, :btw, &)
end

#buildDefinition

Produces the frozen Definition.

Returns:

Raises:



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/inquirex/dsl/flow_builder.rb', line 85

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

  Definition.new(
    start_step_id: @start_step_id,
    nodes:         @nodes,
    id:            @flow_id,
    version:       @flow_version,
    meta:          @meta
  )
end

#confirm(id) ⇒ Object

Defines a yes/no confirmation gate (collects a boolean answer).

Parameters:

  • id (Symbol)

    step id



77
78
79
# File 'lib/inquirex/dsl/flow_builder.rb', line 77

def confirm(id, &)
  add_step(id, :confirm, &)
end

#header(id) ⇒ Object

Defines a section heading step (no input collected).

Parameters:

  • id (Symbol)

    step id



56
57
58
# File 'lib/inquirex/dsl/flow_builder.rb', line 56

def header(id, &)
  add_step(id, :header, &)
end

#meta(title: nil, subtitle: nil, brand: nil) ⇒ Object

Sets frontend metadata: title, subtitle, and brand information.

Parameters:

  • title (String, nil) (defaults to: nil)
  • subtitle (String, nil) (defaults to: nil)
  • brand (Hash, nil) (defaults to: nil)

    e.g. { name: “Acme”, color: “#2563eb” }



32
33
34
35
36
# File 'lib/inquirex/dsl/flow_builder.rb', line 32

def meta(title: nil, subtitle: nil, brand: nil)
  @meta[:title] = title if title
  @meta[:subtitle] = subtitle if subtitle
  @meta[:brand] = brand if brand
end

#say(id) ⇒ Object

Defines an informational message step (no input collected).

Parameters:

  • id (Symbol)

    step id



49
50
51
# File 'lib/inquirex/dsl/flow_builder.rb', line 49

def say(id, &)
  add_step(id, :say, &)
end

#start(step_id) ⇒ Object

Sets the entry step id for the flow.

Parameters:

  • step_id (Symbol)


23
24
25
# File 'lib/inquirex/dsl/flow_builder.rb', line 23

def start(step_id)
  @start_step_id = step_id
end

#warning(id) ⇒ Object

Defines an important alert step (no input collected).

Parameters:

  • id (Symbol)

    step id



70
71
72
# File 'lib/inquirex/dsl/flow_builder.rb', line 70

def warning(id, &)
  add_step(id, :warning, &)
end