waterfall 1.0.6 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e52a3c6940723b7e9c59482c7e171194d3cea775
4
- data.tar.gz: 6ea7ab247654ef7ded20428d387c160d8a9d4e95
3
+ metadata.gz: 27aca92eae9decca2d3a32be3293985de0b219e1
4
+ data.tar.gz: d9e95c5a4a7aa9438f06bd67337bd5a87e7c8dd8
5
5
  SHA512:
6
- metadata.gz: 89b68643618d10d2401c99780981e4e5dc684b90deed6c889c2bf7c237000ca8e530427d7b69229716dee7425559282d40946e0490e62bb3aa09f5e637dae788
7
- data.tar.gz: 184a675a17e17452f99b163fb3761ad9b7abbbd4b83cc2164f46d6402de5556e2dc0786dccb4ecf2357b1df357c8b124a55f086a19724429f42c5e18daf6c823
6
+ metadata.gz: e178dab7e10f42a2215c17cd991d3af286a07908bd2e4c3d4f8f3b8769ee576a8c9e455af3a57c037a866bd3693aecf940894ef601f4684f3b4bbfeb15873f73
7
+ data.tar.gz: eac428e1c45e83e652451bf37fa972bbe03db7ad90c61c47a8597d7b512852d33c48d5010531fc78b52b006a9dc8bee71dd5d5b80f8931c7e9138f18addbd2de
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- waterfall (1.0.5)
4
+ waterfall (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -53,4 +53,4 @@ DEPENDENCIES
53
53
  waterfall!
54
54
 
55
55
  BUNDLED WITH
56
- 1.13.6
56
+ 1.14.4
data/README.md CHANGED
@@ -1,4 +1,3 @@
1
- ![Waterfall Logo](http://apneadiving.github.io/images/waterfall_logo.png)
2
1
  [![Code Climate](https://codeclimate.com/github/apneadiving/waterfall/badges/gpa.svg)](https://codeclimate.com/github/apneadiving/waterfall)
3
2
  [![Test Coverage](https://codeclimate.com/github/apneadiving/waterfall/badges/coverage.svg)](https://codeclimate.com/github/apneadiving/waterfall/coverage)
4
3
  [![Build Status](https://travis-ci.org/apneadiving/waterfall.svg?branch=master)](https://travis-ci.org/apneadiving/waterfall)
@@ -9,7 +8,14 @@ Chain ruby commands, and treat them like a flow, which provides a new approach t
9
8
 
10
9
  When logic is complicated, waterfalls show their true power and let you write intention revealing code. Above all they excel at chaining services.
11
10
 
12
- General presentation blog post there: [Chain services objects like a boss](https://medium.com/p/chain-service-objects-like-a-boss-35d0b83606ab) and upcoming book: [the Unhappy path](https://leanpub.com/the-unhappy-path)
11
+ #### Material
12
+ <a href="https://leanpub.com/the-unhappy-path"> <img align="left" width="80" height="116" src="https://apneadiving.github.io/images/unhappy-path.png"> </a>
13
+ Upcoming book about failure management patterns, leveraging the gem: [The Unhappy path](https://leanpub.com/the-unhappy-path)
14
+
15
+ General presentation blog post there: [Chain services objects like a boss](https://medium.com/p/chain-service-objects-like-a-boss-35d0b83606ab).
16
+
17
+ Reach me [@apneadiving](https://twitter.com/apneadiving)
18
+
13
19
 
14
20
  #### Overview
15
21
 
@@ -19,7 +25,7 @@ Here is a basic representation:
19
25
  - green, the flow goes on, `chain` by `chain`
20
26
  - red its bypassed and only `on_dam` blocks are executed.
21
27
 
22
- ![Waterfall Logo](http://apneadiving.github.io/images/waterfall_principle.png)
28
+ ![Waterfall Principle](https://apneadiving.github.io/images/waterfall_principle.png)
23
29
 
24
30
  #### Example
25
31
 
@@ -176,6 +182,18 @@ else
176
182
  self.chain { Service3.new }
177
183
  end
178
184
  ```
185
+ ### Halting chain
186
+ Sometimes you have a flow and you need a return value. You can use `halt_chain`, which is executed whether or not the flow is dammed. It returns what the block returns. As a consequence, it cannot be chained anymore, so it must be the last command:
187
+
188
+ ```ruby
189
+ self.halt_chain do |outflow, error_pool|
190
+ if error_pool
191
+ # what you want to return on error
192
+ else
193
+ # what you want to return from the outflow
194
+ end
195
+ end
196
+ ```
179
197
 
180
198
  ### Rails and transactions
181
199
  I'm used to wrap every single object involving database interactions within transactions, so it can be rolled back on error.
@@ -224,6 +242,10 @@ end
224
242
  ```
225
243
  The huge benefit is that if you call services from services, everything will be rolled back.
226
244
 
245
+ ### FYI
246
+
247
+ `Flow` is just an alias for the `Wf` class, so just use the one you prefer :)
248
+
227
249
  Examples / Presentations
228
250
  ========================
229
251
  - Check the [wiki for other examples](https://github.com/apneadiving/waterfall/wiki/Refactoring-examples).
@@ -1,3 +1,7 @@
1
+ ===1.1.0
2
+ - Removed `chain_wf`.
3
+ - Introduced `halt_chain`
4
+
1
5
  ===1.0.6
2
6
  Alias Wf with Flow
3
7
 
@@ -33,11 +33,6 @@ module Waterfall
33
33
  end
34
34
  end
35
35
 
36
- def chain_wf(mapping_hash = nil, &block)
37
- warn "[DEPRECATION] `chain_wf` is deprecated. Please use `chain` instead."
38
- chain(mapping_hash, &block)
39
- end
40
-
41
36
  def on_dam(&block)
42
37
  ::Waterfall::OnDam
43
38
  .new(self)
@@ -55,6 +50,10 @@ module Waterfall
55
50
  self
56
51
  end
57
52
 
53
+ def halt_chain(&block)
54
+ yield(outflow, error_pool)
55
+ end
56
+
58
57
  def dammed?
59
58
  !error_pool.nil?
60
59
  end
@@ -1,3 +1,3 @@
1
1
  module Waterfall
2
- VERSION = "1.0.6"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -27,6 +27,11 @@ describe Flow do
27
27
  expect(wf.outflow.foo).to eq 1
28
28
  end
29
29
 
30
+ it 'returns itself to enable chaining' do
31
+ expect(wf.chain{ }).to eq wf
32
+ expect(wf.on_dam{ }).to eq wf
33
+ end
34
+
30
35
  it 'chain yields outflow and waterfall itself' do
31
36
  wf.chain do |outflow, waterfall|
32
37
  expect(outflow).to eq wf.outflow
@@ -98,8 +103,24 @@ describe Flow do
98
103
  expect { wf.chain(:foo) { Flow.new } }.to raise_error(Waterfall::IncorrectChainingArgumentError, Waterfall::Chain::MAPPING_ERROR_MESSAGE)
99
104
  end
100
105
 
101
- it 'warns against chain_wf' do
102
- expect(wf).to receive :warn
103
- wf.chain_wf { Flow.new }
106
+ describe 'halt_chain' do
107
+ it "yields expected values" do
108
+ wf.chain(:foo) { 1 }.halt_chain do |outflow, error_pool|
109
+ expect(outflow).to eq wf.outflow
110
+ expect(error_pool).to eq wf.error_pool
111
+ end
112
+ end
113
+
114
+ it "yields expected values even if dammed" do
115
+ wf.chain(:foo) { 1 }.dam("errr").halt_chain do |outflow, error_pool|
116
+ expect(outflow).to eq wf.outflow
117
+ expect(error_pool).to eq wf.error_pool
118
+ end
119
+ end
120
+
121
+ it "returns what the block returns" do
122
+ expect(wf.halt_chain { "return value" }).to eq "return value"
123
+ end
124
+
104
125
  end
105
126
  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.0.6
4
+ version: 1.1.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: 2017-08-18 00:00:00.000000000 Z
11
+ date: 2017-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler