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.2.1"

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.with_reversible_flowObject

Returns the value of attribute with_reversible_flow.



17
18
19
# File 'lib/waterfall.rb', line 17

def with_reversible_flow
  @with_reversible_flow
end

Instance Attribute Details

#error_poolObject (readonly)

Returns the value of attribute error_pool.



11
12
13
# File 'lib/waterfall.rb', line 11

def error_pool
  @error_pool
end

Instance Method Details

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



37
38
39
40
41
42
43
# File 'lib/waterfall.rb', line 37

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) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/waterfall.rb', line 52

def dam(obj)
  raise IncorrectDamArgumentError.new("You cant dam with a falsy object") unless obj
  _wf_run do
    @error_pool = obj
    _reverse_flows(true)
  end
end

#dammed?Boolean

Returns:

  • (Boolean)


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

def dammed?
  !error_pool.nil?
end

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

Yields:



60
61
62
# File 'lib/waterfall.rb', line 60

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

#has_flown?Boolean

Returns:

  • (Boolean)


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

def has_flown?
  !! @has_flown
end

#is_waterfall?Boolean

Returns:

  • (Boolean)


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

def is_waterfall?
  true
end

#on_dam(&block) ⇒ Object



45
46
47
48
49
50
# File 'lib/waterfall.rb', line 45

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

#outflowObject



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

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

#reverse_flowObject



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

def reverse_flow
end

#update_outflow(key, value) ⇒ Object



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

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

#when_falsy(&block) ⇒ Object



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

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

#when_truthy(&block) ⇒ Object



31
32
33
34
35
# File 'lib/waterfall.rb', line 31

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