solid_use_case 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/solid_use_case/either.rb +11 -11
- data/lib/solid_use_case/version.rb +1 -1
- data/spec/either_spec.rb +17 -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: 50ac616300a91a04f78a2a4934820b138485bda7
|
4
|
+
data.tar.gz: 343dcee1c7461a90bb05d9f690ec3e3adfbc9040
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bd5934d65811ec08f7a36086c114319fc08dfcd6928af573753107bbdfee9c15faa88e1512e8cba2062bff8433f047aca97fbac2c9fe1b18f5713e414dab300
|
7
|
+
data.tar.gz: 47984ff8d514e5b4ec51f785fae3c7495a1b22a41529890ba3ea2c2793f710076d515011373f8e3d2dd0c954187356341e65dd0b045d84e398f323b496e95f80
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
gem 'solid_use_case', '~> 2.1.
|
9
|
+
gem 'solid_use_case', '~> 2.1.1'
|
10
10
|
|
11
11
|
And then execute:
|
12
12
|
|
@@ -42,7 +42,7 @@ class UserSignup
|
|
42
42
|
|
43
43
|
def save_user(params)
|
44
44
|
user = params[:user]
|
45
|
-
if user.save
|
45
|
+
if !user.save
|
46
46
|
fail :user_save_failed, :user => user
|
47
47
|
else
|
48
48
|
continue(params)
|
@@ -103,7 +103,7 @@ Because we're using consistent successes and failures, we can use different func
|
|
103
103
|
|
104
104
|
```ruby
|
105
105
|
# NOTE: The following assumes that #post_comment returns a Success or Failure
|
106
|
-
video = Video.
|
106
|
+
video = Video.find_by(id: params[:video_id])
|
107
107
|
check_exists(video).and_then { post_comment(params) }
|
108
108
|
|
109
109
|
# NOTE: The following assumes that #find_tag and #create_tag both return a Success or Failure
|
@@ -3,24 +3,24 @@ module SolidUseCase
|
|
3
3
|
|
4
4
|
def run(inputs)
|
5
5
|
steps = self.class.instance_variable_get("@__steps").clone
|
6
|
-
|
7
|
-
return
|
6
|
+
current_result = Success(inputs)
|
7
|
+
return current_result unless steps
|
8
8
|
|
9
9
|
while steps.count > 0
|
10
10
|
next_step = steps.shift
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
current_result = current_result.and_then do
|
13
|
+
if next_step.is_a?(Class) && (next_step.respond_to? :can_run_either?) && next_step.can_run_either?
|
14
|
+
next_step.run(current_result.value)
|
15
|
+
elsif next_step.is_a?(Symbol)
|
16
|
+
self.send(next_step, current_result.value)
|
17
|
+
else
|
18
|
+
raise "Invalid step type: #{next_step.inspect}"
|
19
|
+
end
|
18
20
|
end
|
19
|
-
|
20
|
-
result = result.and(subresult)
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
current_result
|
24
24
|
end
|
25
25
|
|
26
26
|
# # # # # #
|
data/spec/either_spec.rb
CHANGED
@@ -77,6 +77,23 @@ describe SolidUseCase::Either do
|
|
77
77
|
expect(result).to be_a_success
|
78
78
|
expect(result.value).to eq(41)
|
79
79
|
end
|
80
|
+
|
81
|
+
class ShortCircuit
|
82
|
+
include SolidUseCase
|
83
|
+
steps :first, :second
|
84
|
+
|
85
|
+
def first(inputs)
|
86
|
+
fail :jump_out_yo
|
87
|
+
end
|
88
|
+
|
89
|
+
def second(inputs)
|
90
|
+
throw "Should not reach this point"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it "doesn't run the next step a failure occures" do
|
95
|
+
expect { ShortCircuit.run }.to_not raise_error
|
96
|
+
end
|
80
97
|
end
|
81
98
|
|
82
99
|
|
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.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gilbert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deterministic
|