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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd6e3cd5ae2df5e4e6121b46e1ad127a9613b39b
4
- data.tar.gz: bd9634100ae693fd84e1a6ed7b2c362395be627b
3
+ metadata.gz: e4fa811a59c1b353ab25f5c56d47c494aab50972
4
+ data.tar.gz: 07657eeaebc676339be72d29373afecff23527f1
5
5
  SHA512:
6
- metadata.gz: 89668b9efe963d440bb839827984a73e2b14ef3f3d1eeb4879a40c80ebf33465cde450685e392a0168b77686024413ff0257e1dcd10e0304ca3fe4c0dea5f90e
7
- data.tar.gz: a425c2ced04535bca474ebff300070664172735bb120a22cea2d4e29b7f8d758042b9a702101d1bc232a373b558fbaa6f4da00b64e57b7b19490142b3b5f2f12
6
+ metadata.gz: 512a8896bbd591e770c78be0d3c8fd3628f824c664020b2d1b430b0a2c718e34dc8cca6661f1387d283368eef54b4e439698bad1d0ca950e3c991aa2c9a25257
7
+ data.tar.gz: ce7e7632e200548d05a87419aa03b8f318c3284f40052b2b792fa1c8afba5246860b67151a1dda8db66e8006c5e26510edad3925833e0ab17499f927140e1447
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- waterfall (1.2.0)
4
+ waterfall (1.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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 :)
@@ -1,3 +1,7 @@
1
+ ===1.2.1
2
+ - Introduced `Waterfall.with_reversible_flow`, makes `reverse_flow` optionnal, may save memory
3
+ - outflow is now lazy loaded
4
+
1
5
  ===1.2.0
2
6
  - Removed `undam`.
3
7
  - Introduced `reverse_flow`
@@ -8,11 +8,20 @@ require 'waterfall/predicates/chain'
8
8
 
9
9
  module Waterfall
10
10
 
11
- attr_reader :error_pool, :outflow
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
@@ -1,3 +1,3 @@
1
1
  module Waterfall
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
@@ -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.0
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: 2017-10-07 00:00:00.000000000 Z
11
+ date: 2018-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler