Module: Hopscotch::StepComposers::Default
Instance Method Summary collapse
-
#call_each(*fns) ⇒ Object
‘call_each` composes a list of functions into a single function which it thens calls, returning the result of the composition.
-
#compose_with_error_handling(*fns) ⇒ Object
Composes a list of functions into a single function.
Instance Method Details
#call_each(*fns) ⇒ Object
‘call_each` composes a list of functions into a single function which it thens calls, returning the result of the composition
Each fn should have the rough type: “‘
- fn
-
void -> ReturnValue
“‘
14 15 16 |
# File 'lib/hopscotch/step_composers/default.rb', line 14 def call_each(*fns) compose_with_error_handling(fns).call end |
#compose_with_error_handling(*fns) ⇒ Object
Composes a list of functions into a single function.
Note that this isn’t a general purpose composition. Note a function here is anything that responds to ‘call` i.e. lambda or a singleton module.
The composed function and each constituent function have the same signature, roughly: “‘
- fn
-
void -> ReturnValue
“‘
Note that ‘void` is used here to mean “takes no arguments”. This is a dead giveaway that functions of this type signature will have side effects.
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hopscotch/step_composers/default.rb', line 31 def compose_with_error_handling(*fns) redcued_fn = fns.flatten.compact.inject do |composed, fn| -> do last_return = composed.call if Hopscotch::Error.error?(last_return) last_return else fn.call end end end redcued_fn || -> { Hopscotch::Step.success! } end |