waterfall 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/changelog.md +5 -0
- data/lib/waterfall.rb +14 -3
- data/lib/waterfall/predicates/chain.rb +1 -1
- data/lib/waterfall/predicates/on_dam.rb +1 -1
- data/lib/waterfall/version.rb +1 -1
- data/spec/wf_object_spec.rb +16 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 078be4fc0c809c19b4dc69414117ed5ab2962cec
|
4
|
+
data.tar.gz: a1dbebd4c474ea3cca0f3d2ac62ca2883d2cbc73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cb114ad14c238c888ee842cc29020a56ce9d554848ba83a60b90bf2faa17a4888d6ff32ad6c2d066379d4107909d252cafa0f55b0741feb3b29b0e233707885
|
7
|
+
data.tar.gz: e21b53012acfcf0555c874c26f8fd3bd490f33e9ff74be1afccb9043625038ed08c6b00bc1daa7502f1a0ddd514f51e461952fa68eeabe3c1d9d10f6b36418c8
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -53,7 +53,7 @@ Flow.new
|
|
53
53
|
.chain(user1: :user) { FetchUser.new(1) }
|
54
54
|
.chain(user2: :user) { FetchUser.new(2) }
|
55
55
|
.chain {|outflow| puts(outflow.user1, outflow.user2) } # report success
|
56
|
-
.on_dam {|error|
|
56
|
+
.on_dam {|error, context| puts(error, context) } # report error
|
57
57
|
```
|
58
58
|
|
59
59
|
Which works like:
|
data/changelog.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
===1.3.0
|
2
|
+
- Introduced `error_pool_context`, providing with the stacktrace leading to the dam
|
3
|
+
- changed `on_dam` signature to pass context to the block
|
4
|
+
- add `Waterfall.caller_locations_length` to limit the number of lines of the stacktrace (default is nil: unlimited)
|
5
|
+
|
1
6
|
===1.2.1
|
2
7
|
- Introduced `Waterfall.with_reversible_flow`, makes `reverse_flow` optionnal, may save memory
|
3
8
|
- outflow is now lazy loaded
|
data/lib/waterfall.rb
CHANGED
@@ -6,17 +6,21 @@ require 'waterfall/predicates/when_falsy'
|
|
6
6
|
require 'waterfall/predicates/when_truthy'
|
7
7
|
require 'waterfall/predicates/chain'
|
8
8
|
|
9
|
+
WATERFALL_PATH = "lib/waterfall"
|
10
|
+
|
9
11
|
module Waterfall
|
10
12
|
|
11
|
-
attr_reader :error_pool
|
13
|
+
attr_reader :error_pool, :error_pool_context
|
12
14
|
|
13
15
|
class IncorrectDamArgumentError < StandardError; end
|
14
16
|
class IncorrectChainingArgumentError < StandardError; end
|
15
17
|
|
16
18
|
class << self
|
17
19
|
attr_accessor :with_reversible_flow
|
20
|
+
attr_accessor :caller_locations_length
|
18
21
|
end
|
19
22
|
@with_reversible_flow = true
|
23
|
+
@caller_locations_length = nil
|
20
24
|
|
21
25
|
def outflow
|
22
26
|
@outflow ||= OpenStruct.new({})
|
@@ -49,16 +53,17 @@ module Waterfall
|
|
49
53
|
self
|
50
54
|
end
|
51
55
|
|
52
|
-
def dam(obj)
|
56
|
+
def dam(obj, context = nil)
|
53
57
|
raise IncorrectDamArgumentError.new("You cant dam with a falsy object") unless obj
|
54
58
|
_wf_run do
|
55
59
|
@error_pool = obj
|
60
|
+
@error_pool_context = context || _error_pool_context
|
56
61
|
_reverse_flows(true)
|
57
62
|
end
|
58
63
|
end
|
59
64
|
|
60
65
|
def halt_chain(&block)
|
61
|
-
yield(outflow, error_pool)
|
66
|
+
yield(outflow, error_pool, error_pool_context)
|
62
67
|
end
|
63
68
|
|
64
69
|
def dammed?
|
@@ -104,6 +109,12 @@ module Waterfall
|
|
104
109
|
yield unless dammed?
|
105
110
|
self
|
106
111
|
end
|
112
|
+
|
113
|
+
def _error_pool_context
|
114
|
+
caller_locations(1, Waterfall.caller_locations_length).reject do |line|
|
115
|
+
line.to_s.include?(WATERFALL_PATH)
|
116
|
+
end
|
117
|
+
end
|
107
118
|
end
|
108
119
|
|
109
120
|
class Wf
|
data/lib/waterfall/version.rb
CHANGED
data/spec/wf_object_spec.rb
CHANGED
@@ -42,12 +42,14 @@ describe Flow do
|
|
42
42
|
it 'isnt dammed by default' do
|
43
43
|
expect(wf.dammed?).to be false
|
44
44
|
expect(wf.error_pool).to eq nil
|
45
|
+
expect(wf.error_pool_context).to be nil
|
45
46
|
end
|
46
47
|
|
47
48
|
it 'is dammed if you dam it!' do
|
48
49
|
wf.dam('error')
|
49
50
|
expect(wf.dammed?).to be true
|
50
51
|
expect(wf.error_pool).to eq 'error'
|
52
|
+
expect(wf.error_pool_context).to be_an Array
|
51
53
|
end
|
52
54
|
|
53
55
|
it 'dam raises if falsy argument sent' do
|
@@ -66,6 +68,15 @@ describe Flow do
|
|
66
68
|
expect(wf.error_pool).to eq 'error'
|
67
69
|
end
|
68
70
|
|
71
|
+
it 'error pool and context values propagate to root flow' do
|
72
|
+
sub_flow = Flow.new
|
73
|
+
sub_flow.chain { sub_flow.dam('errr') }
|
74
|
+
wf.chain { sub_flow }
|
75
|
+
|
76
|
+
expect(wf).to be_dammed
|
77
|
+
expect(wf.error_pool_context).to eq sub_flow.error_pool_context
|
78
|
+
end
|
79
|
+
|
69
80
|
it 'doesnt execute chain blocks once dammed' do
|
70
81
|
expect do
|
71
82
|
wf.when_falsy { false }.dam { 'error' }.chain { raise 'I should not be executed because of damming before me' }
|
@@ -85,9 +96,10 @@ describe Flow do
|
|
85
96
|
expect(listener).to have_received :failure
|
86
97
|
end
|
87
98
|
|
88
|
-
it 'on_dam blocks yield error pool, outflow and waterfall' do
|
89
|
-
wf.dam('errr').on_dam do |error_pool, outflow, waterfall|
|
99
|
+
it 'on_dam blocks yield error pool, error context, outflow and waterfall' do
|
100
|
+
wf.dam('errr').on_dam do |error_pool, error_pool_context, outflow, waterfall|
|
90
101
|
expect(error_pool).to eq wf.error_pool
|
102
|
+
expect(error_pool_context).to eq wf.error_pool_context
|
91
103
|
expect(outflow).to eq wf.outflow
|
92
104
|
expect(waterfall).to eq wf
|
93
105
|
end
|
@@ -106,9 +118,10 @@ describe Flow do
|
|
106
118
|
end
|
107
119
|
|
108
120
|
it "yields expected values even if dammed" do
|
109
|
-
wf.chain(:foo) { 1 }.dam("errr").halt_chain do |outflow, error_pool|
|
121
|
+
wf.chain(:foo) { 1 }.dam("errr").halt_chain do |outflow, error_pool, error_pool_context|
|
110
122
|
expect(outflow).to eq wf.outflow
|
111
123
|
expect(error_pool).to eq wf.error_pool
|
124
|
+
expect(error_pool_context).to eq wf.error_pool_context
|
112
125
|
end
|
113
126
|
end
|
114
127
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: waterfall
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Roth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|