Class: Waterfall::Chain
Constant Summary collapse
- MAPPING_ERROR_MESSAGE =
"When chaining waterfalls, you must pass a mapping hash to pass data from one to the other"
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(root, mapping_or_var_name) ⇒ Chain
constructor
A new instance of Chain.
- #map_waterfalls(child_waterfall, mapping) ⇒ Object
Methods inherited from Base
Constructor Details
Instance Method Details
#call ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/waterfall/predicates/chain.rb', line 8 def call output = yield(*yield_args) if waterfall?(output) map_waterfalls(output, @mapping_or_var_name || {}) else @root.update_outflow(@mapping_or_var_name, output) if @mapping_or_var_name end end |
#map_waterfalls(child_waterfall, mapping) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/waterfall/predicates/chain.rb', line 18 def map_waterfalls(child_waterfall, mapping) child_waterfall.call unless child_waterfall.has_flown? raise IncorrectChainingArgumentError.new(MAPPING_ERROR_MESSAGE) unless mapping.is_a?(Hash) mapping.each do |k, v| @root.update_outflow(k, child_waterfall.outflow[v]) end @root.send :_add_executed_flow, child_waterfall if child_waterfall.dammed? @root.dam child_waterfall.error_pool end self end |