Module: Waterfall

Included in:
Wf
Defined in:
lib/waterfall.rb,
lib/waterfall/version.rb,
lib/waterfall/predicates/base.rb,
lib/waterfall/predicates/chain.rb,
lib/waterfall/predicates/on_dam.rb,
lib/waterfall/predicates/when_falsy.rb,
lib/waterfall/predicates/when_truthy.rb

Defined Under Namespace

Classes: Base, Chain, IncorrectChainingArgumentError, IncorrectDamArgumentError, OnDam, WhenFalsy, WhenTruthy

Constant Summary collapse

VERSION =
"1.3.0"

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.caller_locations_lengthObject

Returns the value of attribute caller_locations_length.



20
21
22
# File 'lib/waterfall.rb', line 20

def caller_locations_length
  @caller_locations_length
end

.with_reversible_flowObject

Returns the value of attribute with_reversible_flow.



19
20
21
# File 'lib/waterfall.rb', line 19

def with_reversible_flow
  @with_reversible_flow
end

Instance Attribute Details

#error_poolObject (readonly)

Returns the value of attribute error_pool.



13
14
15
# File 'lib/waterfall.rb', line 13

def error_pool
  @error_pool
end

#error_pool_contextObject (readonly)

Returns the value of attribute error_pool_context.



13
14
15
# File 'lib/waterfall.rb', line 13

def error_pool_context
  @error_pool_context
end

Instance Method Details

#chain(mapping_or_var_name = nil, &block) ⇒ Object



41
42
43
44
45
46
47
# 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) ⇒ Object



56
57
58
59
60
61
62
63
# 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?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/waterfall.rb', line 69

def dammed?
  !error_pool.nil?
end

#halt_chain {|outflow, error_pool, error_pool_context| ... } ⇒ Object



65
66
67
# File 'lib/waterfall.rb', line 65

def halt_chain(&block)
  yield(outflow, error_pool, error_pool_context)
end

#has_flown?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/waterfall.rb', line 77

def has_flown?
  !! @has_flown
end

#is_waterfall?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/waterfall.rb', line 73

def is_waterfall?
  true
end

#on_dam(&block) ⇒ Object



49
50
51
52
53
54
# File 'lib/waterfall.rb', line 49

def on_dam(&block)
  ::Waterfall::OnDam
    .new(self)
    .call(&block)
  self
end

#outflowObject



25
26
27
# File 'lib/waterfall.rb', line 25

def outflow
  @outflow ||= OpenStruct.new({})
end

#reverse_flowObject



86
87
# File 'lib/waterfall.rb', line 86

def reverse_flow
end

#update_outflow(key, value) ⇒ Object



81
82
83
84
# File 'lib/waterfall.rb', line 81

def update_outflow(key, value)
  @outflow[key] = value
  self
end

#when_falsy(&block) ⇒ Object



29
30
31
32
33
# 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) ⇒ Object



35
36
37
38
39
# File 'lib/waterfall.rb', line 35

def when_truthy(&block)
  ::Waterfall::WhenTruthy.new(self).tap do |handler|
    _wf_run { handler.call(&block) }
  end
end