Class: Hubbado::Sequence::Pipeline
- Inherits:
-
Object
- Object
- Hubbado::Sequence::Pipeline
- Defined in:
- lib/hubbado/sequence/pipeline.rb
Overview
Railway-style step runner that backs the Sequencer mixin’s ‘pipeline(ctx)` helper. Not part of the public API — sequencers reach it through the helper.
Instance Method Summary collapse
-
#initialize(ctx, dispatcher:) ⇒ Pipeline
constructor
A new instance of Pipeline.
-
#invoke(name, *args, **kwargs) ⇒ Object
‘invoke(:name, *args, **kwargs)` calls a declared dependency on the dispatcher: gets it via `dispatcher.send(name)` (the reader), then invokes it with `(ctx, *args, **kwargs)`.
- #result ⇒ Object
-
#step(name) ⇒ Object
‘step(:name)` dispatches to `dispatcher.send(name, ctx)`.
- #transaction ⇒ Object
Constructor Details
#initialize(ctx, dispatcher:) ⇒ Pipeline
Returns a new instance of Pipeline.
7 8 9 10 11 12 |
# File 'lib/hubbado/sequence/pipeline.rb', line 7 def initialize(ctx, dispatcher:) @ctx = ctx @trail = [] @failed_result = nil @dispatcher = dispatcher end |
Instance Method Details
#invoke(name, *args, **kwargs) ⇒ Object
‘invoke(:name, *args, **kwargs)` calls a declared dependency on the dispatcher: gets it via `dispatcher.send(name)` (the reader), then invokes it with `(ctx, *args, **kwargs)`. Same trail recording, failure short-circuiting, and lenient return convention as `step`.
Use this for any declared dependency — macros (‘Macros::Model::Find`) and nested sequencers (`Seqs::Present`) alike. Use `step` for local instance methods like `def deserialize_contract(ctx)`.
35 36 37 38 39 40 |
# File 'lib/hubbado/sequence/pipeline.rb', line 35 def invoke(name, *args, **kwargs) return self if @failed_result record(name, invoke_dependency(name, args, kwargs)) self end |
#result ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/hubbado/sequence/pipeline.rb', line 57 def result if @failed_result @failed_result else Result.ok(@ctx, trail: @trail.dup) end end |
#step(name) ⇒ Object
‘step(:name)` dispatches to `dispatcher.send(name, ctx)`. The method is treated as successful unless it explicitly returns a failed `Result`; any other return value (nil, false, a model, `Result.ok`) continues the pipeline with the same ctx. Only `Result.fail(…)` / `failure(ctx, code: …)` short-circuits.
19 20 21 22 23 24 |
# File 'lib/hubbado/sequence/pipeline.rb', line 19 def step(name) return self if @failed_result record(name, invoke_step(name)) self end |
#transaction ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/hubbado/sequence/pipeline.rb', line 42 def transaction return self if @failed_result if defined?(::ActiveRecord::Base) ::ActiveRecord::Base.transaction do yield(self) raise ::ActiveRecord::Rollback if @failed_result end else yield(self) end self end |