Class: Wurk::Flow::Chain
- Inherits:
-
Object
- Object
- Wurk::Flow::Chain
- Defined in:
- lib/wurk/flow/chain.rb
Overview
A flow with one path through it, where every step is handed the step before it.
Wurk::Flow.chain do |c|
c.job(FetchJob, 'https://example.com')
c.job(ParseJob) # gets FetchJob's result
c.job(StoreJob, 'reports') # gets ParseJob's result
end.run
No new machinery: this is Builder's pipe: applied to the node
before, once per step. Everything a flow does — atomic creation, the
caps, failure propagation, abandon — applies unchanged, and a chain is
inspectable as the graph it is rather than as a second kind of object.
The argument arrives last, after whatever the step declared for itself:
c.job(StoreJob, 'reports') runs StoreJob#perform('reports', result).
Prepending it would mean a step's own arguments change position depending
on where in the chain it sits.
Instance Method Summary collapse
-
#initialize(builder) ⇒ Chain
constructor
A new instance of Chain.
-
#job(klass) ⇒ Flow::Node
Add the next step.
Constructor Details
#initialize(builder) ⇒ Chain
Returns a new instance of Chain.
24 25 26 27 |
# File 'lib/wurk/flow/chain.rb', line 24 def initialize(builder) @builder = builder @previous = nil end |
Instance Method Details
#job(klass) ⇒ Flow::Node
Add the next step.
pipe: nil on the first step is exactly pipe: not being passed —
Builder#job treats them the same — so there is no first-step
branch to get wrong.
37 38 39 |
# File 'lib/wurk/flow/chain.rb', line 37 def job(klass, *, **) @previous = @builder.job(klass, *, pipe: @previous, **) end |