Class: Inquirex::DSL::StepBuilder
- Inherits:
-
Object
- Object
- Inquirex::DSL::StepBuilder
- Includes:
- RuleHelpers
- Defined in:
- lib/inquirex/dsl/step_builder.rb
Overview
Builds a single Node from a step DSL block. Used by FlowBuilder for each verb (ask, say, header, btw, warning, confirm). Includes RuleHelpers for transition conditions and skip_if expressions.
Instance Method Summary collapse
-
#build(id) ⇒ Node
Builds the Node for the given step id.
-
#compute {|Answers| ... } ⇒ Object
Registers a compute block: auto-calculates a value from answers, not shown to user.
-
#default(value = nil, &block) ⇒ Object
Sets a default value for this step (shown pre-filled; user can change it).
-
#initialize(verb) ⇒ StepBuilder
constructor
A new instance of StepBuilder.
-
#options(list) ⇒ Object
Sets the list of options for :enum or :multi_enum steps.
-
#question(text) ⇒ Object
Sets the prompt/question text for collecting steps.
-
#skip_if(rule) ⇒ Object
Sets a rule that skips this step entirely when true.
-
#text(content) ⇒ Object
Sets the display text for non-collecting steps (say/header/btw/warning).
-
#transition(to:, if_rule: nil, requires_server: false) ⇒ Object
Adds a conditional transition.
-
#type(value) ⇒ Object
Sets the input data type for :ask steps.
Methods included from RuleHelpers
#all, #any, #contains, #equals, #greater_than, #less_than, #not_empty
Constructor Details
#initialize(verb) ⇒ StepBuilder
Returns a new instance of StepBuilder.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/inquirex/dsl/step_builder.rb', line 11 def initialize(verb) @verb = verb @type = nil @question = nil @text = nil @options = nil @transitions = [] @skip_if = nil @default = nil @compute = nil end |
Instance Method Details
#build(id) ⇒ Node
Builds the Node for the given step id.
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/inquirex/dsl/step_builder.rb', line 85 def build(id) Node.new( id:, verb: @verb, type: resolve_type, question: @question, text: @text, options: @options, transitions: @transitions, skip_if: @skip_if, default: @default ) end |
#compute {|Answers| ... } ⇒ Object
Registers a compute block: auto-calculates a value from answers, not shown to user. The computed value is stored server-side only and stripped from JSON serialization.
77 78 79 |
# File 'lib/inquirex/dsl/step_builder.rb', line 77 def compute(&block) @compute = block end |
#default(value = nil, &block) ⇒ Object
Sets a default value for this step (shown pre-filled; user can change it). Can be a static value or a proc receiving collected answers so far.
69 70 71 |
# File 'lib/inquirex/dsl/step_builder.rb', line 69 def default(value = nil, &block) @default = block || value end |
#options(list) ⇒ Object
Sets the list of options for :enum or :multi_enum steps. Accepts an Array (option keys) or a Hash (key => label).
44 45 46 |
# File 'lib/inquirex/dsl/step_builder.rb', line 44 def (list) @options = list end |
#question(text) ⇒ Object
Sets the prompt/question text for collecting steps.
31 32 33 |
# File 'lib/inquirex/dsl/step_builder.rb', line 31 def question(text) @question = text end |
#skip_if(rule) ⇒ Object
Sets a rule that skips this step entirely when true. The step is omitted from the user’s path and no answer is recorded.
61 62 63 |
# File 'lib/inquirex/dsl/step_builder.rb', line 61 def skip_if(rule) @skip_if = rule end |
#text(content) ⇒ Object
Sets the display text for non-collecting steps (say/header/btw/warning).
37 38 39 |
# File 'lib/inquirex/dsl/step_builder.rb', line 37 def text(content) @text = content end |
#transition(to:, if_rule: nil, requires_server: false) ⇒ Object
Adds a conditional transition. First matching transition wins.
53 54 55 |
# File 'lib/inquirex/dsl/step_builder.rb', line 53 def transition(to:, if_rule: nil, requires_server: false) @transitions << Transition.new(target: to, rule: if_rule, requires_server:) end |
#type(value) ⇒ Object
Sets the input data type for :ask steps.
25 26 27 |
# File 'lib/inquirex/dsl/step_builder.rb', line 25 def type(value) @type = value end |