usecasing 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +11 -7
- data/lib/usecasing/base.rb +5 -1
- data/lib/usecasing/context.rb +8 -0
- data/lib/usecasing/version.rb +1 -1
- data/spec/execution_order_spec.rb +0 -1
- data/spec/spec_helper.rb +6 -0
- data/spec/usecase_base_spec.rb +40 -0
- data/usecasing.gemspec +5 -4
- metadata +28 -14
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODY5ZTA4M2JkYTNkNzhiNmNlZWYzNWUxNjkzOWNmYzA4MzBhYWU1Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzRmODIwMzk5ZWFjMDE1MWJjZjM5NDRhNjVhY2Q5NGVhOTgxMzcwYQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTM1ODI3ODVjYzg4NDBjMTU1ZWFhNzIxYjg1NjAxZDJkYzRmOGIyNDJiMTg2
|
10
|
+
Y2Y5YjBhYTdmN2IzZTBmZmYwZGVkMjA5NWM0ODI4YmQzNDZhNjA4ZjllZDE0
|
11
|
+
MTgxZjdmYWE0NjFjZDY0MTJkN2VkOTM0NTFiMDVhZGJhZWU0MjE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODFhNWU5YTZkYzUxZTdiMjNhODVmYTIyOWQ3YTliM2E0MzUyY2VmMTRmMGI0
|
14
|
+
MjUwNGY2YmM3MGYwNjljMGYwMDAxZDdjNjNkNjdmNTUxNDVhNzBkMmI2Y2U3
|
15
|
+
ZGYyMzI1MDQ5MGEyODhlMDc0NzVkNDNkNTE1MjMzYzc3MDE0MDk=
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
[![Build Status](https://secure.travis-ci.org/tdantas/usecasing.png)](http://travis-ci.org/tdantas/usecasing)
|
7
7
|
[![Dependency Status](https://gemnasium.com/tdantas/usecasing.svg)](https://gemnasium.com/tdantas/usecasing)
|
8
|
-
|
8
|
+
[![Coverage Status](https://coveralls.io/repos/tdantas/usecasing/badge.png)](https://coveralls.io/r/tdantas/usecasing)
|
9
9
|
|
10
10
|
Add this line to your application's Gemfile:
|
11
11
|
|
@@ -72,14 +72,15 @@ This is what we call context, the usecase context will be shared between all cha
|
|
72
72
|
|
73
73
|
````
|
74
74
|
class FindInvoice < UseCase::Base
|
75
|
+
|
76
|
+
def before
|
77
|
+
@user = context.curent_user
|
78
|
+
end
|
75
79
|
|
76
80
|
def perform
|
77
81
|
|
78
|
-
# available because it was added in the controller context
|
79
|
-
user = context.current_user
|
80
|
-
|
81
82
|
# we could do that in one before_filter
|
82
|
-
invoice = user.invoices.find(context.invoice_id)
|
83
|
+
invoice = @user.invoices.find(context.invoice_id)
|
83
84
|
|
84
85
|
# asign to the context make available to all chain
|
85
86
|
context.invoice = invoice
|
@@ -113,9 +114,12 @@ So, after validate, we already know that the invoice exists and it is ready to b
|
|
113
114
|
````
|
114
115
|
class FinalizeInvoice < UseCase::Base
|
115
116
|
|
117
|
+
def before
|
118
|
+
@invoice = context.invoice
|
119
|
+
end
|
120
|
+
|
116
121
|
def perform
|
117
|
-
invoice
|
118
|
-
invoice.finalize! #update database with finalize state
|
122
|
+
@invoice.finalize! #update database with finalize state
|
119
123
|
context.customer = invoice.customer
|
120
124
|
end
|
121
125
|
|
data/lib/usecasing/base.rb
CHANGED
@@ -35,7 +35,7 @@ module UseCase
|
|
35
35
|
ctx = Context.new(context)
|
36
36
|
executed = []
|
37
37
|
execution_order.each do |usecase|
|
38
|
-
break
|
38
|
+
break if !ctx.success? || ctx.stopped?
|
39
39
|
executed.push(usecase)
|
40
40
|
yield usecase, ctx
|
41
41
|
end
|
@@ -66,6 +66,10 @@ module UseCase
|
|
66
66
|
def perform; end
|
67
67
|
def rollback; end
|
68
68
|
|
69
|
+
def stop!
|
70
|
+
context.stop!
|
71
|
+
end
|
72
|
+
|
69
73
|
def failure(key, value)
|
70
74
|
@context.failure(key, value)
|
71
75
|
end
|
data/lib/usecasing/context.rb
CHANGED
data/lib/usecasing/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/usecase_base_spec.rb
CHANGED
@@ -278,6 +278,46 @@ describe UseCase::Base do
|
|
278
278
|
|
279
279
|
end
|
280
280
|
|
281
|
+
context 'stopping the flow' do
|
282
|
+
|
283
|
+
FirstCase = Class.new(UseCase::Base) do
|
284
|
+
def perform
|
285
|
+
context.wizzard_name = "Gandalf"
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
StopCase = Class.new(UseCase::Base) do
|
290
|
+
def perform
|
291
|
+
context.result = "YOUUUU SHHHAAALLLL NOOOTTTT PASSSSSS!"
|
292
|
+
stop!
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
UnachievableCase = Class.new(UseCase::Base) do
|
297
|
+
def perform
|
298
|
+
context.result = "Still here! Muahaha!"
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
Base = Class.new(UseCase::Base) do
|
303
|
+
depends FirstCase, StopCase, UnachievableCase
|
304
|
+
end
|
305
|
+
|
306
|
+
let(:subject) { Base.perform }
|
307
|
+
|
308
|
+
it 'returns variables inserted by first dependency' do
|
309
|
+
expect(subject.wizzard_name).to eq("Gandalf")
|
310
|
+
end
|
311
|
+
|
312
|
+
it 'does not have variables inserted by unachievable case' do
|
313
|
+
expect(subject.result).to eq("YOUUUU SHHHAAALLLL NOOOTTTT PASSSSSS!")
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'is successfull' do
|
317
|
+
expect(subject.success?).to be_true
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
281
321
|
|
282
322
|
describe '#before' do
|
283
323
|
|
data/usecasing.gemspec
CHANGED
@@ -19,8 +19,9 @@ Gem::Specification.new do |gem|
|
|
19
19
|
|
20
20
|
|
21
21
|
#development dependecy
|
22
|
-
gem.add_development_dependency "rspec"
|
23
|
-
gem.add_development_dependency "rake"
|
24
|
-
gem.add_development_dependency "mocha"
|
25
|
-
|
22
|
+
gem.add_development_dependency "rspec",'~> 2.14.1'
|
23
|
+
gem.add_development_dependency "rake", '~> 10.1'
|
24
|
+
gem.add_development_dependency "mocha",'~> 1.0.0'
|
25
|
+
gem.add_development_dependency "coveralls", '~> 0.7'
|
26
|
+
|
26
27
|
end
|
metadata
CHANGED
@@ -1,57 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usecasing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thiago Dantas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.14.1
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.14.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '10.1'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '10.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: mocha
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 1.0.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 1.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.7'
|
55
69
|
description: UseCase Driven approach to your code
|
56
70
|
email:
|
57
71
|
- thiago.teixeira.dantas@gmail.com
|