Module: Teckel::Chain::ClassMethods
- Defined in:
- lib/teckel/chain.rb
Instance Attribute Summary collapse
-
#runner() ⇒ Class
readonly
protected
The Runner class.
Instance Method Summary collapse
-
#around(callable = nil, &block) ⇒ Proc, {#call}
Set or get the optional around hook.
-
#call(input) ⇒ Teckel::Result, Teckel::Chain::StepFailure
The primary interface to call the chain with the given input.
- #clone ⇒ Object
- #dup ⇒ Object
-
#errors ⇒ <Class>
List of all possible errors.
-
#finalize! ⇒ self
Disallow any further changes to this Chain.
-
#input ⇒ Class
The expected input for this chain.
-
#output ⇒ Class
The expected output for this chain.
-
#runner(klass = nil) ⇒ Object
protected
Overwrite the default runner.
-
#step(name, operation) ⇒ Object
Declare a Operation as a named step.
Instance Attribute Details
#runner() ⇒ Class (readonly, protected)
Returns The Runner class.
|
|
# File 'lib/teckel/chain.rb', line 323
|
Instance Method Details
#around(callable = nil, &block) ⇒ Proc, {#call}
Set or get the optional around hook. A Hook might be given as a block or anything callable. The execution of the chain is yielded to this hook. The first argument being the callable chain (Runner) and the second argument the input data. The hook also needs to return the result.
319 320 321 |
# File 'lib/teckel/chain.rb', line 319 def around(callable = nil, &block) @config.for(:around, callable || block) end |
#call(input) ⇒ Teckel::Result, Teckel::Chain::StepFailure
The primary interface to call the chain with the given input.
341 342 343 344 345 346 347 348 |
# File 'lib/teckel/chain.rb', line 341 def call(input) runner = self.runner.new(@steps) if around around.call(runner, input) else runner.call(input) end end |
#clone ⇒ Object
370 371 372 373 374 375 376 377 378 379 |
# File 'lib/teckel/chain.rb', line 370 def clone if frozen? super else super.tap do |copy| copy.instance_variable_set(:@steps, @steps.dup) copy.instance_variable_set(:@config, @config.dup) end end end |
#dup ⇒ Object
362 363 364 365 366 367 |
# File 'lib/teckel/chain.rb', line 362 def dup super.tap do |copy| copy.instance_variable_set(:@steps, @steps.dup) copy.instance_variable_set(:@config, @config.dup) end end |
#errors ⇒ <Class>
List of all possible errors
262 263 264 265 266 267 |
# File 'lib/teckel/chain.rb', line 262 def errors @steps.each_with_object([]) do |e, m| err = e.last&.error m << err if err end end |
#finalize! ⇒ self
Disallow any further changes to this Chain.
354 355 356 357 358 359 |
# File 'lib/teckel/chain.rb', line 354 def finalize! freeze @steps.freeze @config.freeze self end |
#input ⇒ Class
The expected input for this chain
250 251 252 |
# File 'lib/teckel/chain.rb', line 250 def input @steps.first&.last&.input end |
#output ⇒ Class
The expected output for this chain
256 257 258 |
# File 'lib/teckel/chain.rb', line 256 def output @steps.last&.last&.output end |
#runner(klass = nil) ⇒ Object (protected)
Overwrite the default runner
330 331 332 |
# File 'lib/teckel/chain.rb', line 330 def runner(klass = nil) @config.for(:runner, klass) { Runner } end |
#step(name, operation) ⇒ Object
Declare a Operation as a named step
275 276 277 |
# File 'lib/teckel/chain.rb', line 275 def step(name, operation) @steps << [name, operation] end |