Module: Trailblazer::Activity::Railway::DSL
- Defined in:
- lib/trailblazer/activity/railway.rb
Defined Under Namespace
Modules: Fail, Pass Classes: State
Constant Summary collapse
- Linear =
Activity::DSL::Linear
- Normalizers =
Instance
Linear::State::Normalizer.new( step: Linear::Normalizer.activity_normalizer( Railway::DSL.normalizer ), # here, we extend the generic FastTrack::step_normalizer with the Activity-specific DSL fail: Linear::Normalizer.activity_normalizer( Railway::DSL.normalizer_for_fail ), pass: Linear::Normalizer.activity_normalizer( Railway::DSL.normalizer_for_pass ), )
Class Method Summary collapse
- .failure_connections ⇒ Object
- .failure_outputs ⇒ Object
- .initial_sequence(failure_end:, initial_sequence:, **path_options) ⇒ Object
- .normalize_path_connections(ctx, flow_options) ⇒ Object
-
.normalize_path_outputs(ctx, flow_options) ⇒ Object
Add :failure output to :outputs.
- .normalizer ⇒ Object
-
.normalizer_for_fail ⇒ Object
Change some parts of the “normal” DSL.normalizer pipeline.
- .normalizer_for_pass ⇒ Object
- .OptionsForState(normalizers: Normalizers, failure_end: Activity::End.new(semantic: :failure), **options) ⇒ Object
-
.step_options(sequence) ⇒ Object
Add Trailblazer::Activity::Railway steps to normalizer path.
Class Method Details
.failure_connections ⇒ Object
112 113 114 |
# File 'lib/trailblazer/activity/railway.rb', line 112 def failure_connections {failure: [Linear::Search.method(:Forward), :failure]} end |
.failure_outputs ⇒ Object
109 110 111 |
# File 'lib/trailblazer/activity/railway.rb', line 109 def failure_outputs {failure: Activity::Output(Activity::Left, :failure)} end |
.initial_sequence(failure_end:, initial_sequence:, **path_options) ⇒ Object
116 117 118 119 |
# File 'lib/trailblazer/activity/railway.rb', line 116 def initial_sequence(failure_end:, initial_sequence:, **) # TODO: this could be an Activity itself but maybe a bit too much for now. sequence = Path::DSL.append_end(initial_sequence, task: failure_end, magnetic_to: :failure, id: "End.failure") end |
.normalize_path_connections(ctx, flow_options) ⇒ Object
102 103 104 105 106 107 |
# File 'lib/trailblazer/activity/railway.rb', line 102 def normalize_path_connections((ctx, ), *) connections = failure_connections.merge(ctx[:connections]) ctx = ctx.merge(connections: connections) return Right, [ctx, ] end |
.normalize_path_outputs(ctx, flow_options) ⇒ Object
Add :failure output to :outputs. TODO: assert that failure_outputs doesn’t override existing :outputs
95 96 97 98 99 100 |
# File 'lib/trailblazer/activity/railway.rb', line 95 def normalize_path_outputs((ctx, ), *) outputs = failure_outputs.merge(ctx[:outputs]) ctx = ctx.merge(outputs: outputs) return Right, [ctx, ] end |
.normalizer ⇒ Object
10 11 12 |
# File 'lib/trailblazer/activity/railway.rb', line 10 def normalizer (Activity::Path::DSL.normalizer) end |
.normalizer_for_fail ⇒ Object
Change some parts of the “normal” normalizer pipeline. TODO: make this easier, even at this step.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/trailblazer/activity/railway.rb', line 17 def normalizer_for_fail sequence = normalizer id = "railway.magnetic_to.fail" task = Fail.method(:merge_magnetic_to) # TODO: use prepend_to_path sequence = Linear::DSL.insert_task(sequence, task: task, magnetic_to: :success, id: id, wirings: [Linear::Search.Forward(Path::DSL.unary_outputs[:success], :success)], sequence_insert: [Linear::Insert.method(:Prepend), "path.wirings"]) id = "railway.connections.fail.success_to_failure" task = Fail.method(:connect_success_to_failure) sequence = Linear::DSL.insert_task(sequence, task: task, magnetic_to: :success, id: id, wirings: [Linear::Search.Forward(Path::DSL.unary_outputs[:success], :success)], sequence_insert: [Linear::Insert.method(:Replace), "path.connections"]) end |
.normalizer_for_pass ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/trailblazer/activity/railway.rb', line 40 def normalizer_for_pass sequence = normalizer id = "railway.connections.pass.failure_to_success" task = Pass.method(:connect_failure_to_success) sequence = Linear::DSL.insert_task(sequence, task: task, magnetic_to: :success, id: id, wirings: [Linear::Search.Forward(Path::DSL.unary_outputs[:success], :success)], sequence_insert: [Linear::Insert.method(:Append), "path.connections"]) end |
.OptionsForState(normalizers: Normalizers, failure_end: Activity::End.new(semantic: :failure), **options) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/trailblazer/activity/railway.rb', line 137 def self.OptionsForState(normalizers: Normalizers, failure_end: Activity::End.new(semantic: :failure), **) = Path::DSL.OptionsForState(). merge(normalizers: normalizers, failure_end: failure_end) initial_sequence = Railway::DSL.initial_sequence(failure_end: failure_end, **) { **, initial_sequence: initial_sequence, } end |
.step_options(sequence) ⇒ Object
Add Trailblazer::Activity::Railway steps to normalizer path.
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/trailblazer/activity/railway.rb', line 80 def (sequence) Path::DSL.prepend_to_path( # this doesn't particularly put the steps after the Path steps. sequence, { "railway.outputs" => method(:normalize_path_outputs), "railway.connections" => method(:normalize_path_connections), }, Linear::Insert.method(:Prepend), "path.wirings" # override where it's added. ) end |