solid_use_case 2.1.2 → 2.2.0

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: 5853f9c2cc3e82eff481ae6b09ada0776056bbfb
4
- data.tar.gz: 763ba2e09c2aa6eed51d07c1115f6d1e86d62df9
3
+ metadata.gz: d6e3bef00a84c7636bd7c5b3e6e6a700257d316c
4
+ data.tar.gz: 7244cda3c14ec38bb836d5740d59884b29c51f59
5
5
  SHA512:
6
- metadata.gz: 0f0648d01b73747acc258c454d0a05aefd706d4dfffaa0e21e73454ee37d654f49d5bcc6bff53131d1e4f84070e6cff2bce56f1efcf0536ea553a10f736ca7bc
7
- data.tar.gz: be6051006b7f0e7a7ae117c2d8a630724e093ded9fb1bd71dd1771ea5e728478568704bfe94baf6c4aabdfb3b43b36d00ebc69bfb7d0e2d27e59e90a9729be63
6
+ metadata.gz: 453b74532fa2aeed6bdfeefc8acb7770dc60f821b8c667c5bdfcf2dabe26a8c12a5678f0e72b5b1f9ef1a180ead828bbaa18aacc37fde72a4590e7ed9cc67685
7
+ data.tar.gz: 36b1cb891c8fc4da1de265dc023e9a56ac9f8a71e43bdb2aefa31b1928d577f5631bf4fc6d1d695197cc4f40ea0ce7cd91933f95d24f44bba4bba5215aa3fa43
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  Add this line to your application's Gemfile:
10
10
 
11
- gem 'solid_use_case', '~> 2.1.2'
11
+ gem 'solid_use_case', '~> 2.2.0'
12
12
 
13
13
  And then execute:
14
14
 
@@ -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 }
@@ -1,3 +1,3 @@
1
1
  module SolidUseCase
2
- VERSION = "2.1.2"
2
+ VERSION = "2.2.0"
3
3
  end
@@ -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.1.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-08 00:00:00.000000000 Z
11
+ date: 2018-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deterministic