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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5810571bbc17faba88269dbdbe7f205d1e28d13b
4
- data.tar.gz: 9576bcb516c93bd5e2f7b71ef1432746c3181f54
3
+ metadata.gz: 50ac616300a91a04f78a2a4934820b138485bda7
4
+ data.tar.gz: 343dcee1c7461a90bb05d9f690ec3e3adfbc9040
5
5
  SHA512:
6
- metadata.gz: 51fbf7ebc22c9ee27484bf6834e00cece81b165b233142d1fde1e7509fac6bddb4c1c050fdf173e59c77cd577d77452c5b6e8a0ecf0e41add6e32bc0bdb2afe5
7
- data.tar.gz: adf744a459a4b8a70febc3bdcc7a0632751e0f0dfb25c895e38df316b8a1bef9bb37cf98bbb0a657846fa4bd6da07a3b7ee71dfdb39d32487af750003c10e306
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.0'
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.find_by_id(params[:video_id])
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
- result = Success(inputs)
7
- return result unless steps
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
- if next_step.is_a?(Class) && (next_step.respond_to? :can_run_either?) && next_step.can_run_either?
13
- subresult = next_step.run(result.value)
14
- elsif next_step.is_a?(Symbol)
15
- subresult = self.send(next_step, result.value)
16
- else
17
- raise "Invalid step type: #{next_step.inspect}"
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
- result
23
+ current_result
24
24
  end
25
25
 
26
26
  # # # # # #
@@ -1,3 +1,3 @@
1
1
  module SolidUseCase
2
- VERSION = "2.1.0"
2
+ VERSION = "2.1.1"
3
3
  end
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.0
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 00:00:00.000000000 Z
11
+ date: 2014-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deterministic