Module: FlowOrganizer::Callable::Branch
- Defined in:
- lib/flow_organizer/callable/branch.rb
Overview
Call the branch which name is returned by ‘branch_callable`.
## Example
“‘ruby FlowOrganizer.call(
list: [
[:branch, ->(number:) { number.even? ? :even : :odd }, {
even: [
->() { some_action },
],
odd: [
->() { some_other_action },
],
},],
],
ctx: { number: rand(1...10) },
) “‘
Class Method Summary collapse
-
.resolve(args:) ⇒ Object
The expected format for ‘:args` is `[:branch, branch_callable, branch_list]`.
Class Method Details
.resolve(args:) ⇒ Object
The expected format for ‘:args` is `[:branch, branch_callable, branch_list]`
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/flow_organizer/callable/branch.rb', line 24 def self.resolve(args:) _, callable, branches = args wrapped_callable = ->(**arguments) do ctx_in = arguments || {} branch_name, _ctx_out = FlowOrganizer.call( list: [callable], ctx: ctx_in, ) status = :ok ctx_out = {} list = branches[branch_name] if list && !list.empty? status, ctx_out = FlowOrganizer.call( list: branches[branch_name], ctx: ctx_in, ) ctx_out = (ctx_out) ? FlowOrganizer::Context.update_context(ctx: ctx_in, local_ctx: ctx_out) : ctx_in end [status, ctx_out] end [:ok, callable: wrapped_callable] end |