Class: Conductor::Workflow::Dsl::SwitchBuilder
- Inherits:
-
Object
- Object
- Conductor::Workflow::Dsl::SwitchBuilder
- Defined in:
- lib/conductor/workflow/dsl/switch_builder.rb
Overview
SwitchBuilder collects switch cases defined in a decide block. It provides on() and otherwise() methods for defining case branches.
Instance Attribute Summary collapse
-
#cases ⇒ Object
readonly
Returns the value of attribute cases.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#expression ⇒ Object
readonly
Returns the value of attribute expression.
Instance Method Summary collapse
-
#initialize(expression, parent_builder) ⇒ SwitchBuilder
constructor
A new instance of SwitchBuilder.
-
#on(value) { ... } ⇒ Object
Define a case branch.
-
#otherwise { ... } ⇒ Object
Define the default case (executed if no cases match).
Constructor Details
#initialize(expression, parent_builder) ⇒ SwitchBuilder
Returns a new instance of SwitchBuilder.
25 26 27 28 29 30 |
# File 'lib/conductor/workflow/dsl/switch_builder.rb', line 25 def initialize(expression, parent_builder) @expression = expression @parent = parent_builder @cases = {} @default = [] end |
Instance Attribute Details
#cases ⇒ Object (readonly)
Returns the value of attribute cases.
23 24 25 |
# File 'lib/conductor/workflow/dsl/switch_builder.rb', line 23 def cases @cases end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
23 24 25 |
# File 'lib/conductor/workflow/dsl/switch_builder.rb', line 23 def default @default end |
#expression ⇒ Object (readonly)
Returns the value of attribute expression.
23 24 25 |
# File 'lib/conductor/workflow/dsl/switch_builder.rb', line 23 def expression @expression end |
Instance Method Details
#on(value) { ... } ⇒ Object
Define a case branch
35 36 37 38 39 40 |
# File 'lib/conductor/workflow/dsl/switch_builder.rb', line 35 def on(value, &block) tasks = [] collector = TaskCollector.new(@parent, tasks) collector.instance_eval(&block) @cases[value.to_s] = tasks end |
#otherwise { ... } ⇒ Object
Define the default case (executed if no cases match)
44 45 46 47 |
# File 'lib/conductor/workflow/dsl/switch_builder.rb', line 44 def otherwise(&block) collector = TaskCollector.new(@parent, @default) collector.instance_eval(&block) end |