waterfall 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -24
- data/changelog.md +15 -3
- data/lib/waterfall.rb +2 -0
- data/lib/waterfall/version.rb +1 -1
- data/spec/chaining_services_spec.rb +1 -1
- data/spec/wf_object_spec.rb +8 -4
- 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: e52a3c6940723b7e9c59482c7e171194d3cea775
|
4
|
+
data.tar.gz: 6ea7ab247654ef7ded20428d387c160d8a9d4e95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89b68643618d10d2401c99780981e4e5dc684b90deed6c889c2bf7c237000ca8e530427d7b69229716dee7425559282d40946e0490e62bb3aa09f5e637dae788
|
7
|
+
data.tar.gz: 184a675a17e17452f99b163fb3761ad9b7abbbd4b83cc2164f46d6402de5556e2dc0786dccb4ecf2357b1df357c8b124a55f086a19724429f42c5e18daf6c823
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ Chain ruby commands, and treat them like a flow, which provides a new approach t
|
|
9
9
|
|
10
10
|
When logic is complicated, waterfalls show their true power and let you write intention revealing code. Above all they excel at chaining services.
|
11
11
|
|
12
|
-
General presentation blog post there: [Chain services objects like a boss](https://medium.com/p/chain-service-objects-like-a-boss-35d0b83606ab).
|
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)
|
13
13
|
|
14
14
|
#### Overview
|
15
15
|
|
@@ -43,11 +43,11 @@ end
|
|
43
43
|
and call / chain:
|
44
44
|
|
45
45
|
```ruby
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
Flow.new
|
47
|
+
.chain(user1: :user) { FetchUser.new(1) }
|
48
|
+
.chain(user2: :user) { FetchUser.new(2) }
|
49
|
+
.chain {|outflow| puts(outflow.user1, outflow.user2) } # report success
|
50
|
+
.on_dam {|error| puts(error) } # report error
|
51
51
|
```
|
52
52
|
|
53
53
|
Which works like:
|
@@ -77,28 +77,30 @@ Wiki contains many details, please check appropriate pages:
|
|
77
77
|
- [Wf Object](https://github.com/apneadiving/waterfall/wiki/Wf-object)
|
78
78
|
- [Testing](https://github.com/apneadiving/waterfall/wiki/Testing)
|
79
79
|
|
80
|
+
### Koans (!)
|
81
|
+
You can try and exercise your understanding of Waterfall using the [Koans here](https://github.com/apneadiving/waterfall_koans)
|
80
82
|
|
81
83
|
## Illustration of chaining
|
82
84
|
Doing
|
83
85
|
```ruby
|
84
|
-
|
85
|
-
|
86
|
+
Flow.new
|
87
|
+
.chain(foo: :bar) { Flow.new.chain(:bar){ 1 } }
|
86
88
|
```
|
87
89
|
|
88
90
|
is the same as doing:
|
89
91
|
|
90
92
|
```ruby
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
93
|
+
Flow.new
|
94
|
+
.chain do |outflow, parent_waterfall|
|
95
|
+
unless parent_waterfall.dammed?
|
96
|
+
child = Wf.new.chain(:bar){ 1 }
|
97
|
+
if child.dammed?
|
98
|
+
parent_waterfall.dam(child.error_pool)
|
99
|
+
else
|
100
|
+
parent_waterfall.ouflow.foo = child.outflow.bar
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
102
104
|
```
|
103
105
|
|
104
106
|
Hopefully you better get the chaining power this way.
|
@@ -117,13 +119,13 @@ end
|
|
117
119
|
You may have noticed that I usually write:
|
118
120
|
|
119
121
|
```ruby
|
120
|
-
|
121
|
-
|
122
|
+
Flow.new
|
123
|
+
.chain { MyWaterfall.new }
|
122
124
|
```
|
123
125
|
instead of
|
124
126
|
```ruby
|
125
|
-
|
126
|
-
|
127
|
+
Flow.new
|
128
|
+
.chain { MyWaterfall.new.call }
|
127
129
|
```
|
128
130
|
Both are the same: if a block returns a waterfall which was not executed, it will execute it (hence the `call` convention)
|
129
131
|
|
@@ -207,7 +209,7 @@ class AuthenticateUser
|
|
207
209
|
attr_reader :user
|
208
210
|
|
209
211
|
def initialize(email, password)
|
210
|
-
@email, @password = email,
|
212
|
+
@email, @password = email, password
|
211
213
|
end
|
212
214
|
|
213
215
|
def call
|
data/changelog.md
CHANGED
@@ -1,6 +1,18 @@
|
|
1
|
-
===1.0.
|
1
|
+
===1.0.6
|
2
|
+
Alias Wf with Flow
|
3
|
+
|
4
|
+
=== 1.0.5
|
5
|
+
- naming: changed flowing to has_flown to clarify its not related to damming
|
6
|
+
- spec change
|
7
|
+
|
8
|
+
=== 1.0.4
|
9
|
+
- add clearer error messages
|
10
|
+
- deprecate chain_wf
|
11
|
+
- prevent from damming falsy values
|
12
|
+
|
13
|
+
=== 1.0.3
|
2
14
|
- Small refactors
|
3
15
|
- if waterfall 1 calls waterfall 2 and waterfall2 is dammed, now waterfall1 is able to get values from waterfall2's outflow
|
4
16
|
|
5
|
-
===1.0.2
|
6
|
-
Initial release
|
17
|
+
=== 1.0.2
|
18
|
+
Initial release
|
data/lib/waterfall.rb
CHANGED
data/lib/waterfall/version.rb
CHANGED
data/spec/wf_object_spec.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
let(:wf) {
|
3
|
+
describe Flow do
|
4
|
+
let(:wf) { Flow.new }
|
5
|
+
|
6
|
+
it 'is aliased' do
|
7
|
+
expect(Flow).to eq Wf
|
8
|
+
end
|
5
9
|
|
6
10
|
it 'is a waterfall' do
|
7
11
|
expect(wf.is_waterfall?).to be true
|
@@ -91,11 +95,11 @@ describe Wf do
|
|
91
95
|
end
|
92
96
|
|
93
97
|
it 'raises if chain waterfall without hash mapping' do
|
94
|
-
expect { wf.chain(:foo) {
|
98
|
+
expect { wf.chain(:foo) { Flow.new } }.to raise_error(Waterfall::IncorrectChainingArgumentError, Waterfall::Chain::MAPPING_ERROR_MESSAGE)
|
95
99
|
end
|
96
100
|
|
97
101
|
it 'warns against chain_wf' do
|
98
102
|
expect(wf).to receive :warn
|
99
|
-
wf.chain_wf {
|
103
|
+
wf.chain_wf { Flow.new }
|
100
104
|
end
|
101
105
|
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.
|
4
|
+
version: 1.0.6
|
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-
|
11
|
+
date: 2017-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|