waterfall 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/Gemfile.lock +2 -2
- data/README.md +3 -4
- data/lib/waterfall.rb +6 -1
- data/lib/waterfall/predicates/chain.rb +6 -0
- data/lib/waterfall/version.rb +1 -1
- data/spec/integration_spec.rb +30 -13
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2918f5c657d78ab72747847b48ca6024995b8cdc
|
4
|
+
data.tar.gz: 473b2b1b9cf9512fb13520523cbf4ae358a005b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ddce902522214cdb5e5cdf939d18a8a1dca0026dd79de3c29ac30c17f3bd7bc6c2abd06c21f8dc67398d3dbf617c3032a67136dd792ffe37b786138a2e1e57f
|
7
|
+
data.tar.gz: 1d17dee11a63dc85b223e3e70e94bd1b35e09df45ff926d2f3a2da8d6ea2eca07d7c56e4124124aa6b97af651e7ab7fdba0d043baa898ed4fcea365cee1ac0e1
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,15 +2,14 @@
|
|
2
2
|
[![Code Climate](https://codeclimate.com/github/apneadiving/waterfall/badges/gpa.svg)](https://codeclimate.com/github/apneadiving/waterfall)
|
3
3
|
[![Test Coverage](https://codeclimate.com/github/apneadiving/waterfall/badges/coverage.svg)](https://codeclimate.com/github/apneadiving/waterfall/coverage)
|
4
4
|
[![Build Status](https://travis-ci.org/apneadiving/waterfall.svg?branch=master)](https://travis-ci.org/apneadiving/waterfall)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/waterfall.svg)](https://badge.fury.io/rb/waterfall)
|
5
6
|
#### Goal
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
It provides a new approach to flow control.
|
8
|
+
Chain ruby commands, and treat them like a flow, which provides a new approach to application control flow.
|
10
9
|
|
11
10
|
When logic is complicated, waterfalls show their true power and let you write intention revealing code. Above all they excel at chaining services.
|
12
11
|
|
13
|
-
General presentation
|
12
|
+
General presentation blog post there: [Chain services objects like a boss](https://medium.com/p/chain-service-objects-like-a-boss-35d0b83606ab).
|
14
13
|
|
15
14
|
#### Overview
|
16
15
|
|
data/lib/waterfall.rb
CHANGED
@@ -10,6 +10,9 @@ module Waterfall
|
|
10
10
|
|
11
11
|
attr_reader :error_pool, :outflow, :flowing, :_wf_rolled_back
|
12
12
|
|
13
|
+
class IncorrectDamArgumentError < StandardError; end
|
14
|
+
class IncorrectChainingArgumentError < StandardError; end
|
15
|
+
|
13
16
|
def when_falsy(&block)
|
14
17
|
handler = ::Waterfall::WhenFalsy.new(self)
|
15
18
|
_wf_run { handler.call(&block) }
|
@@ -31,6 +34,7 @@ module Waterfall
|
|
31
34
|
end
|
32
35
|
|
33
36
|
def chain_wf(mapping_hash = nil, &block)
|
37
|
+
warn "[DEPRECATION] `chain_wf` is deprecated. Please use `chain` instead."
|
34
38
|
chain(mapping_hash, &block)
|
35
39
|
end
|
36
40
|
|
@@ -42,12 +46,13 @@ module Waterfall
|
|
42
46
|
end
|
43
47
|
|
44
48
|
def dam(obj)
|
49
|
+
raise IncorrectDamArgumentError.new("You cant dam with a falsy object") unless obj
|
45
50
|
@error_pool = obj
|
46
51
|
self
|
47
52
|
end
|
48
53
|
|
49
54
|
def undam
|
50
|
-
|
55
|
+
@error_pool = nil
|
51
56
|
self
|
52
57
|
end
|
53
58
|
|
@@ -18,6 +18,8 @@ module Waterfall
|
|
18
18
|
def map_waterfalls(child_waterfall, mapping)
|
19
19
|
child_waterfall.call unless child_waterfall.flowing?
|
20
20
|
|
21
|
+
raise IncorrectChainingArgumentError.new(mapping_error_message) unless mapping.is_a?(Hash)
|
22
|
+
|
21
23
|
mapping.each do |k, v|
|
22
24
|
@root.update_outflow(k, child_waterfall.outflow[v])
|
23
25
|
end
|
@@ -28,5 +30,9 @@ module Waterfall
|
|
28
30
|
|
29
31
|
self
|
30
32
|
end
|
33
|
+
|
34
|
+
def mapping_error_message
|
35
|
+
"When chaining waterfalls, you must pass a mapping hash to pass data from one to the other"
|
36
|
+
end
|
31
37
|
end
|
32
38
|
end
|
data/lib/waterfall/version.rb
CHANGED
data/spec/integration_spec.rb
CHANGED
@@ -2,6 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'Wf' do
|
4
4
|
let(:wf) { Wf.new }
|
5
|
+
let(:error_string) { 'error' }
|
5
6
|
|
6
7
|
describe "chain" do
|
7
8
|
|
@@ -23,10 +24,10 @@ describe 'Wf' do
|
|
23
24
|
context "wf internals" do
|
24
25
|
it "dam from within" do
|
25
26
|
wf
|
26
|
-
.chain {|outflow, waterfall| waterfall.dam(
|
27
|
+
.chain {|outflow, waterfall| waterfall.dam(error_string) }
|
27
28
|
|
28
29
|
expect(wf.dammed?).to be true
|
29
|
-
expect(wf.error_pool).to eq
|
30
|
+
expect(wf.error_pool).to eq error_string
|
30
31
|
end
|
31
32
|
|
32
33
|
it "expose child waterfall outflow even if dammed (or at least what was computed)" do
|
@@ -55,15 +56,19 @@ describe 'Wf' do
|
|
55
56
|
describe "chaining waterfalls" do
|
56
57
|
|
57
58
|
shared_examples "a waterfall chain" do
|
58
|
-
describe '
|
59
|
+
describe 'chain waterfall' do
|
59
60
|
it "takes expected vars only and rename them" do
|
60
61
|
wf
|
61
|
-
.
|
62
|
+
.chain(baz: :foo) { waterfall }
|
62
63
|
|
63
64
|
expect(wf.outflow.foo).to be nil
|
64
65
|
expect(wf.outflow.bar).to be nil
|
65
66
|
expect(wf.outflow.baz).to eq waterfall.outflow.foo
|
66
67
|
end
|
68
|
+
|
69
|
+
it 'raises if chain waterfall without hash mapping' do
|
70
|
+
expect { wf.chain(:foo) { waterfall } }.to raise_error(Waterfall::IncorrectChainingArgumentError)
|
71
|
+
end
|
67
72
|
end
|
68
73
|
end
|
69
74
|
|
@@ -116,7 +121,7 @@ describe 'Wf' do
|
|
116
121
|
wf
|
117
122
|
.chain { wf.dam('dammed') if dam? }
|
118
123
|
.when_falsy { my_proc.call(bool) }
|
119
|
-
.dam {
|
124
|
+
.dam { error_string }
|
120
125
|
.chain { @foo = 1 }
|
121
126
|
end
|
122
127
|
|
@@ -125,13 +130,13 @@ describe 'Wf' do
|
|
125
130
|
|
126
131
|
it "when actually falsy" do
|
127
132
|
action false
|
128
|
-
expect(wf.error_pool).to eq
|
133
|
+
expect(wf.error_pool).to eq error_string
|
129
134
|
expect(@foo).to_not eq 1
|
130
135
|
end
|
131
136
|
|
132
137
|
it "when actually truthy" do
|
133
138
|
action true
|
134
|
-
expect(wf.error_pool).to_not eq
|
139
|
+
expect(wf.error_pool).to_not eq error_string
|
135
140
|
expect(@foo).to eq 1
|
136
141
|
end
|
137
142
|
end
|
@@ -154,7 +159,7 @@ describe 'Wf' do
|
|
154
159
|
wf
|
155
160
|
.chain { wf.dam('dammed') if dam? }
|
156
161
|
.when_truthy { my_proc.call(bool) }
|
157
|
-
.dam {
|
162
|
+
.dam { error_string }
|
158
163
|
.chain { @foo = 1 }
|
159
164
|
end
|
160
165
|
|
@@ -163,13 +168,13 @@ describe 'Wf' do
|
|
163
168
|
|
164
169
|
it "when actually falsy" do
|
165
170
|
action false
|
166
|
-
expect(wf.error_pool).to_not eq
|
171
|
+
expect(wf.error_pool).to_not eq error_string
|
167
172
|
expect(@foo).to eq 1
|
168
173
|
end
|
169
174
|
|
170
175
|
it "when actually truthy" do
|
171
176
|
action true
|
172
|
-
expect(wf.error_pool).to eq
|
177
|
+
expect(wf.error_pool).to eq error_string
|
173
178
|
expect(@foo).to_not eq 1
|
174
179
|
end
|
175
180
|
end
|
@@ -195,24 +200,36 @@ describe 'Wf' do
|
|
195
200
|
end
|
196
201
|
|
197
202
|
def self.error
|
198
|
-
'
|
203
|
+
'error'
|
199
204
|
end
|
200
205
|
end
|
201
206
|
|
202
207
|
it "error propagates" do
|
203
208
|
wf
|
204
209
|
.chain { FailingChain.new }
|
205
|
-
.chain
|
210
|
+
.chain { @foo = 1 }
|
206
211
|
|
207
212
|
expect(@foo).to_not eq 1
|
208
213
|
expect(wf.error_pool).to eq FailingChain.error
|
209
214
|
end
|
210
215
|
end
|
211
216
|
|
217
|
+
describe "dam" do
|
218
|
+
it "raises if falsy argument sent" do
|
219
|
+
expect { wf.dam(nil) }.to raise_error(Waterfall::IncorrectDamArgumentError)
|
220
|
+
end
|
221
|
+
|
222
|
+
it "dams with truthy argument" do
|
223
|
+
wf.dam(error_string)
|
224
|
+
expect(wf.error_pool).to eq error_string
|
225
|
+
expect(wf.dammed?).to be true
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
212
229
|
describe "undam" do
|
213
230
|
it "flow goes back to green path" do
|
214
231
|
wf
|
215
|
-
.chain { wf.dam(
|
232
|
+
.chain { wf.dam(error_string) }
|
216
233
|
.on_dam { wf.undam }
|
217
234
|
.chain { @foo = 1 }
|
218
235
|
.on_dam { raise('shouldnt happen') }
|
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.4
|
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: 2017-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
version: '0'
|
128
128
|
requirements: []
|
129
129
|
rubyforge_project:
|
130
|
-
rubygems_version: 2.
|
130
|
+
rubygems_version: 2.5.1
|
131
131
|
signing_key:
|
132
132
|
specification_version: 4
|
133
133
|
summary: A slice of functional programming to chain ruby services and blocks. Make
|