solid_use_case 2.1.2 → 2.2.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 +4 -4
- data/README.md +1 -1
- data/lib/solid_use_case/either.rb +13 -0
- data/lib/solid_use_case/version.rb +1 -1
- data/spec/either_spec.rb +46 -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: d6e3bef00a84c7636bd7c5b3e6e6a700257d316c
|
4
|
+
data.tar.gz: 7244cda3c14ec38bb836d5740d59884b29c51f59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 453b74532fa2aeed6bdfeefc8acb7770dc60f821b8c667c5bdfcf2dabe26a8c12a5678f0e72b5b1f9ef1a180ead828bbaa18aacc37fde72a4590e7ed9cc67685
|
7
|
+
data.tar.gz: 36b1cb891c8fc4da1de265dc023e9a56ac9f8a71e43bdb2aefa31b1928d577f5631bf4fc6d1d695197cc4f40ea0ce7cd91933f95d24f44bba4bba5215aa3fa43
|
data/README.md
CHANGED
@@ -35,6 +35,19 @@ module SolidUseCase
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def check_each(array, continue_with: array)
|
39
|
+
failure = nil
|
40
|
+
array.find do |item|
|
41
|
+
item_result = yield(item)
|
42
|
+
if item_result.is_a?(Failure)
|
43
|
+
failure = item_result
|
44
|
+
true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
failure || continue(continue_with)
|
49
|
+
end
|
50
|
+
|
38
51
|
def attempt
|
39
52
|
attempt_all do
|
40
53
|
try { yield }
|
data/spec/either_spec.rb
CHANGED
@@ -132,6 +132,52 @@ describe SolidUseCase::Either do
|
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
+
describe 'Helpers' do
|
136
|
+
class CheckEachHelper
|
137
|
+
include SolidUseCase
|
138
|
+
|
139
|
+
def success_1
|
140
|
+
vals = [:x, :y]
|
141
|
+
check_each(vals) {|v| v}
|
142
|
+
end
|
143
|
+
|
144
|
+
def success_2
|
145
|
+
vals = [:x, :y]
|
146
|
+
check_each(vals, continue_with: 999) {|v| v}
|
147
|
+
end
|
148
|
+
|
149
|
+
def failure_1(goods)
|
150
|
+
vals = [5, 10, 0, 15]
|
151
|
+
check_each(vals) do |val|
|
152
|
+
if val != 0
|
153
|
+
goods.push(val)
|
154
|
+
else
|
155
|
+
fail :zero
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
it "checks an array" do
|
162
|
+
result = CheckEachHelper.new.success_1
|
163
|
+
expect(result).to be_a_success
|
164
|
+
expect(result.value).to eq([:x, :y])
|
165
|
+
end
|
166
|
+
|
167
|
+
it "continues with a value" do
|
168
|
+
result = CheckEachHelper.new.success_2
|
169
|
+
expect(result).to be_a_success
|
170
|
+
expect(result.value).to eq(999)
|
171
|
+
end
|
172
|
+
|
173
|
+
it "fails on first" do
|
174
|
+
goods = []
|
175
|
+
result = CheckEachHelper.new.failure_1(goods)
|
176
|
+
expect(result).to fail_with(:zero)
|
177
|
+
expect(goods).to eq([5, 10])
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
135
181
|
describe 'Literals' do
|
136
182
|
it "creates a success literal" do
|
137
183
|
s = SolidUseCase::Either.success(10)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solid_use_case
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gilbert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deterministic
|