Module: Hopscotch::Runners::Default
Instance Method Summary collapse
-
#call(fn, failure:, success:) ⇒ Object
Execute
fnwithin anActiveRecordtransaction. -
#call_each(*fns, failure:, success:) ⇒ Object
call_eachcomposes a list of functions into a single function which it then passes along to acallto perform the workflow logic.
Instance Method Details
#call(fn, failure:, success:) ⇒ Object
Execute fn within an ActiveRecord transaction.
Rough types:
fn :: void -> ReturnValue
failure :: value -> NilClass
success :: value -> NilClass
# or
success :: void -> NilClass
If fn returns an ErrorValue, roll back the transaction and call failure with the unwrapped error value.
Otherwise commit the transaction and call success.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/hopscotch/runners/default.rb', line 20 def call(fn, failure:, success:) error = nil result = nil ActiveRecord::Base.transaction do result = fn.call if Hopscotch::Error.error?(result) error = result raise ActiveRecord::Rollback end end if error failure.call(error.value) else success.arity == 1 ? success.call(result) : success.call end end |
#call_each(*fns, failure:, success:) ⇒ Object
call_each composes a list of functions into a single function
which it then passes along to a call to perform the workflow logic.
Each fn should have the rough type:
fn :: void -> ReturnValue
48 49 50 |
# File 'lib/hopscotch/runners/default.rb', line 48 def call_each(*fns, failure:, success:) call ::Hopscotch::StepComposers::Default.compose_with_error_handling(*fns), failure: failure, success: success end |