Module: Gilmour::Composers
- Included in:
- Backend
- Defined in:
- lib/gilmour/composers.rb
Defined Under Namespace
Classes: AndAnd, Batch, Compose, Parallel, Pipeline, Request
Instance Method Summary collapse
-
#andand(*spec) ⇒ Object
Same as compose this composition does not pass data from one step to the next.
-
#batch(*spec) ⇒ Object
Same a compose, except that no errors are checked and the pipeline executes all steps unconditionally and sequentially.
-
#compose(*spec) ⇒ Object
Create a Compose pipeline as per the spec.
- #parallel(*spec) ⇒ Object
- #sync(*spec, &blk) ⇒ Object
Instance Method Details
#andand(*spec) ⇒ Object
Same as compose this composition does not pass data from one step to the next. Execution halts on the first error It is roughly equivalent to the unix construct
cmd1 && cmd2 && cmd3
149 150 151 |
# File 'lib/gilmour/composers.rb', line 149 def andand(*spec) AndAnd.new(self, spec.flatten) end |
#batch(*spec) ⇒ Object
Same a compose, except that no errors are checked and the pipeline executes all steps unconditionally and sequentially. It is roughly equivalent to the unix construct
cmd1; cmd2; cmd3
OR
(cmd1; cmd2; cmd3)
Params:
record-
If this is false, only the output of the last step
is passed to the block passed to execute. If true, all outputs are collected in an array and passed to the block
194 195 196 |
# File 'lib/gilmour/composers.rb', line 194 def batch(*spec) Batch.new(self, spec.flatten) end |
#compose(*spec) ⇒ Object
Create a Compose pipeline as per the spec. This is roughly equivalent to the following unix construct
cmd1 | cmd2 | cmd3 ...
The spec is an array of hashes, each describing a request topic and message. The message is optional. If present, this message is merged into the output of the previous step, before passing it as the input. Eg, below, if msg2 was a Hash, it would be merged into the output from the subscriber of topic1, and the merged hash would be sent as the request body to topic2
[
{topic: topic1, message: msg1},
{topic: topic2, message: msg2},
...
]
Instead of a hash, a spec item can also be a callable (proc or lambda). In that case, the output of the previous step is passed through the callable, and the return value of the callable is sent as the input to the next step.
In place of a hash or callable, it is also possible to have any kind of composition itself, allowing the creation of nested compositions. See examples in the source code.
121 122 123 |
# File 'lib/gilmour/composers.rb', line 121 def compose(*spec) Compose.new(self, spec.flatten) end |