Class: Inquirex::DSL::FlowBuilder
- Inherits:
-
Object
- Object
- Inquirex::DSL::FlowBuilder
- 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).
Constant Summary collapse
- THEME_KEY_ALIASES =
Maps snake_case theme keys (idiomatic in Ruby) to the camelCase names the JS widget (inquirex-js ThemeOverrides) expects on the wire.
{ on_brand: :onBrand, text_muted: :textMuted, header_font: :headerFont }.freeze
Instance Method Summary collapse
-
#accumulator(name, type: :decimal, default: nil) ⇒ Object
Declares a named running total the flow accumulates into as answers come in.
-
#ask(id) { ... } ⇒ Object
Defines a question step that collects typed input from the user.
-
#btw(id) ⇒ Object
Defines an admonition or sidebar note step (no input collected).
-
#build ⇒ Definition
Produces the frozen Definition.
-
#confirm(id) ⇒ Object
Defines a yes/no confirmation gate (collects a boolean answer).
-
#header(id) ⇒ Object
Defines a section heading step (no input collected).
-
#initialize(id: nil, version: "1.0.0") ⇒ FlowBuilder
constructor
A new instance of FlowBuilder.
-
#meta(title: nil, subtitle: nil, brand: nil, theme: nil) ⇒ Object
Sets frontend metadata: title, subtitle, brand, and theme.
-
#say(id) ⇒ Object
Defines an informational message step (no input collected).
-
#send_email(**opts) { ... } ⇒ void
Declares an email the host application builds and delivers after the flow finishes, from the collected answers.
-
#start(step_id) ⇒ Object
Sets the entry step id for the flow.
-
#warning(id) ⇒ Object
Defines an important alert step (no input collected).
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.
12 13 14 15 16 17 18 19 20 |
# 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 = {} @accumulators = {} @send_emails = [] end |
Instance Method Details
#accumulator(name, type: :decimal, default: nil) ⇒ Object
Declares a named running total the flow accumulates into as answers come in.
The :price accumulator is the common lead-qualification use case; others
(e.g. :complexity, :credit_score) work identically.
A :text accumulator is filled by the engine rather than by
accumulate declarations: it collects everything the user was shown
and every answer they gave, which is what an LLM summarize step
reads. See Accumulator.
36 37 38 39 |
# File 'lib/inquirex/dsl/flow_builder.rb', line 36 def accumulator(name, type: :decimal, default: nil) sym = name.to_sym @accumulators[sym] = Accumulator.new(name: sym, type:, default:) end |
#ask(id) { ... } ⇒ Object
Defines a question step that collects typed input from the user.
76 77 78 |
# File 'lib/inquirex/dsl/flow_builder.rb', line 76 def ask(id, &) add_step(id, :ask, &) end |
#btw(id) ⇒ Object
Defines an admonition or sidebar note step (no input collected).
97 98 99 |
# File 'lib/inquirex/dsl/flow_builder.rb', line 97 def btw(id, &) add_step(id, :btw, &) end |
#build ⇒ Definition
Produces the frozen Definition.
160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/inquirex/dsl/flow_builder.rb', line 160 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, accumulators: @accumulators, send_emails: @send_emails ) end |
#confirm(id) ⇒ Object
Defines a yes/no confirmation gate (collects a boolean answer).
111 112 113 |
# File 'lib/inquirex/dsl/flow_builder.rb', line 111 def confirm(id, &) add_step(id, :confirm, &) end |
#header(id) ⇒ Object
Defines a section heading step (no input collected).
90 91 92 |
# File 'lib/inquirex/dsl/flow_builder.rb', line 90 def header(id, &) add_step(id, :header, &) end |
#meta(title: nil, subtitle: nil, brand: nil, theme: nil) ⇒ Object
Sets frontend metadata: title, subtitle, brand, and theme.
65 66 67 68 69 70 |
# File 'lib/inquirex/dsl/flow_builder.rb', line 65 def (title: nil, subtitle: nil, brand: nil, theme: nil) @meta[:title] = title if title @meta[:subtitle] = subtitle if subtitle @meta[:brand] = brand if brand @meta[:theme] = normalize_theme(theme) if theme end |
#say(id) ⇒ Object
Defines an informational message step (no input collected).
83 84 85 |
# File 'lib/inquirex/dsl/flow_builder.rb', line 83 def say(id, &) add_step(id, :say, &) end |
#send_email(**opts) { ... } ⇒ void
This method returns an undefined value.
Declares an email the host application builds and delivers after the flow finishes, from the collected answers. Declarations run in order; gate with a serializable rule via the if: option. This is the only completion declaration the core DSL carries — richer post-completion behavior belongs to the host application.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/inquirex/dsl/flow_builder.rb', line 141 def send_email(**opts, &block) rule = opts.delete(:if) params = opts if block builder = SendEmailBuilder.new builder.instance_eval(&block) params = params.merge(builder.params) end begin @send_emails << SendEmail.new(**params, rule:) rescue ArgumentError => e raise Errors::DefinitionError, "send_email: #{e.}" end end |
#start(step_id) ⇒ Object
Sets the entry step id for the flow.
44 45 46 |
# File 'lib/inquirex/dsl/flow_builder.rb', line 44 def start(step_id) @start_step_id = step_id end |
#warning(id) ⇒ Object
Defines an important alert step (no input collected).
104 105 106 |
# File 'lib/inquirex/dsl/flow_builder.rb', line 104 def warning(id, &) add_step(id, :warning, &) end |