waterfall 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +8 -0
- data/changelog.md +4 -0
- data/lib/waterfall.rb +12 -2
- data/lib/waterfall/version.rb +1 -1
- data/spec/wf_object_spec.rb +17 -0
- 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: e4fa811a59c1b353ab25f5c56d47c494aab50972
|
4
|
+
data.tar.gz: 07657eeaebc676339be72d29373afecff23527f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 512a8896bbd591e770c78be0d3c8fd3628f824c664020b2d1b430b0a2c718e34dc8cca6661f1387d283368eef54b4e439698bad1d0ca950e3c991aa2c9a25257
|
7
|
+
data.tar.gz: ce7e7632e200548d05a87419aa03b8f318c3284f40052b2b792fa1c8afba5246860b67151a1dda8db66e8006c5e26510edad3925833e0ab17499f927140e1447
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -242,6 +242,14 @@ end
|
|
242
242
|
```
|
243
243
|
The huge benefit is that if you call services from services, everything will be rolled back.
|
244
244
|
|
245
|
+
### Undo
|
246
|
+
|
247
|
+
If you get to dam a flow, this would trigger the `reverse_flow` method in all Services previously executed.
|
248
|
+
|
249
|
+
`reverse_flow` is not executed on the service which just failed, consider the `on_dam` hook in this case.
|
250
|
+
|
251
|
+
Take this as a hook to undo whatever you need to undo if things go wrong. Yet, you probably do not need to bother about databases inserts: this is the purpose of `with_transaction`.
|
252
|
+
|
245
253
|
### FYI
|
246
254
|
|
247
255
|
`Flow` is just an alias for the `Wf` class, so just use the one you prefer :)
|
data/changelog.md
CHANGED
data/lib/waterfall.rb
CHANGED
@@ -8,11 +8,20 @@ require 'waterfall/predicates/chain'
|
|
8
8
|
|
9
9
|
module Waterfall
|
10
10
|
|
11
|
-
attr_reader :error_pool
|
11
|
+
attr_reader :error_pool
|
12
12
|
|
13
13
|
class IncorrectDamArgumentError < StandardError; end
|
14
14
|
class IncorrectChainingArgumentError < StandardError; end
|
15
15
|
|
16
|
+
class << self
|
17
|
+
attr_accessor :with_reversible_flow
|
18
|
+
end
|
19
|
+
@with_reversible_flow = true
|
20
|
+
|
21
|
+
def outflow
|
22
|
+
@outflow ||= OpenStruct.new({})
|
23
|
+
end
|
24
|
+
|
16
25
|
def when_falsy(&block)
|
17
26
|
::Waterfall::WhenFalsy.new(self).tap do |handler|
|
18
27
|
_wf_run { handler.call(&block) }
|
@@ -75,6 +84,7 @@ module Waterfall
|
|
75
84
|
protected
|
76
85
|
|
77
86
|
def _reverse_flows(skip_self)
|
87
|
+
return unless Waterfall.with_reversible_flow
|
78
88
|
return if @flow_reversed
|
79
89
|
@flow_reversed = true
|
80
90
|
reverse_flow unless skip_self
|
@@ -84,13 +94,13 @@ module Waterfall
|
|
84
94
|
end
|
85
95
|
|
86
96
|
def _add_executed_flow(flow)
|
97
|
+
return unless Waterfall.with_reversible_flow
|
87
98
|
@_executed_flows ||= []
|
88
99
|
@_executed_flows.push(flow)
|
89
100
|
end
|
90
101
|
|
91
102
|
def _wf_run
|
92
103
|
@has_flown = true
|
93
|
-
@outflow ||= OpenStruct.new({})
|
94
104
|
yield unless dammed?
|
95
105
|
self
|
96
106
|
end
|
data/lib/waterfall/version.rb
CHANGED
data/spec/wf_object_spec.rb
CHANGED
@@ -169,5 +169,22 @@ describe Flow do
|
|
169
169
|
|
170
170
|
action
|
171
171
|
end
|
172
|
+
|
173
|
+
context "without reversible flow" do
|
174
|
+
around do |example|
|
175
|
+
Waterfall.with_reversible_flow = false
|
176
|
+
example.run
|
177
|
+
Waterfall.with_reversible_flow = true
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'doesnt call reverse_flow, ever' do
|
181
|
+
expect(sub_sub_flow2).to_not receive(:reverse_flow)
|
182
|
+
expect(sub_sub_flow1).to_not receive(:reverse_flow)
|
183
|
+
expect(sub_sub_sub_flow1).to_not receive(:reverse_flow)
|
184
|
+
expect(sub_flow1).to_not receive(:reverse_flow)
|
185
|
+
|
186
|
+
action
|
187
|
+
end
|
188
|
+
end
|
172
189
|
end
|
173
190
|
end
|
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.2.
|
4
|
+
version: 1.2.1
|
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: 2018-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|