module Waterfall
Constants
- VERSION
Attributes
caller_locations_length[RW]
with_reversible_flow[RW]
error_pool[R]
error_pool_context[R]
Public Instance Methods
chain(mapping_or_var_name = nil, &block)
click to toggle source
# File lib/waterfall.rb, line 41 def chain(mapping_or_var_name = nil, &block) _wf_run do ::Waterfall::Chain .new(self, mapping_or_var_name) .call(&block) end end
dam(obj, context = nil)
click to toggle source
# File lib/waterfall.rb, line 56 def dam(obj, context = nil) raise IncorrectDamArgumentError.new("You cant dam with a falsy object") unless obj _wf_run do @error_pool = obj @error_pool_context = context || _error_pool_context _reverse_flows(true) end end
dammed?()
click to toggle source
# File lib/waterfall.rb, line 69 def dammed? !error_pool.nil? end
halt_chain() { |outflow, error_pool, error_pool_context| ... }
click to toggle source
# File lib/waterfall.rb, line 65 def halt_chain(&block) yield(outflow, error_pool, error_pool_context) end
has_flown?()
click to toggle source
# File lib/waterfall.rb, line 77 def has_flown? !! @has_flown end
is_waterfall?()
click to toggle source
# File lib/waterfall.rb, line 73 def is_waterfall? true end
on_dam(&block)
click to toggle source
# File lib/waterfall.rb, line 49 def on_dam(&block) ::Waterfall::OnDam .new(self) .call(&block) self end
outflow()
click to toggle source
# File lib/waterfall.rb, line 25 def outflow @outflow ||= OpenStruct.new({}) end
reverse_flow()
click to toggle source
# File lib/waterfall.rb, line 86 def reverse_flow end
update_outflow(key, value)
click to toggle source
# File lib/waterfall.rb, line 81 def update_outflow(key, value) @outflow[key] = value self end
when_falsy(&block)
click to toggle source
# File lib/waterfall.rb, line 29 def when_falsy(&block) ::Waterfall::WhenFalsy.new(self).tap do |handler| _wf_run { handler.call(&block) } end end
when_truthy(&block)
click to toggle source
# File lib/waterfall.rb, line 35 def when_truthy(&block) ::Waterfall::WhenTruthy.new(self).tap do |handler| _wf_run { handler.call(&block) } end end
Protected Instance Methods
_add_executed_flow(flow)
click to toggle source
# File lib/waterfall.rb, line 101 def _add_executed_flow(flow) return unless Waterfall.with_reversible_flow @_executed_flows ||= [] @_executed_flows.push(flow) end
_error_pool_context()
click to toggle source
# File lib/waterfall.rb, line 113 def _error_pool_context caller_locations(1, Waterfall.caller_locations_length).reject do |line| line.to_s.include?(WATERFALL_PATH) end end
_reverse_flows(skip_self)
click to toggle source
# File lib/waterfall.rb, line 91 def _reverse_flows(skip_self) return unless Waterfall.with_reversible_flow return if @flow_reversed @flow_reversed = true reverse_flow unless skip_self (@_executed_flows || []).reverse_each do |f| f.send :_reverse_flows, false end end
_wf_run() { || ... }
click to toggle source
# File lib/waterfall.rb, line 107 def _wf_run @has_flown = true yield unless dammed? self end