usecasing 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +29 -0
- data/lib/usecasing/context.rb +7 -3
- data/lib/usecasing/version.rb +1 -1
- data/spec/context_spec.rb +6 -2
- data/spec/usecase_base_spec.rb +12 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTcyYWZhMWNjZmRmZWIyYzI0Yzc4NTY5ZDMyNzY2MWViYmI1ZmJkOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
M2ZlZmViZGM4MGIwMzIyOWExMmFiMjkyZGVkYjJiNzk2NTY2MDdkNg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzQzZTk4MmEzNGU4MjlkMjA5MWQ1MDRhNWQyZGE5MDc0ODdjODAzOTEwOGY0
|
10
|
+
NmJjM2EzMGQzZDZlZWYwZGRkMzJiMTdjOGE1MWU1YTBiZjZkYmM5YTNlMmEx
|
11
|
+
NmIzNmMxOGE0NGM1NWQ0MDIyYjYyMDA3ZmJhMmI3Yzk3ZTIzYjM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzQ3MGQ0Y2Q5MDdiOTRkZmUxNWNiMTg1ODYzZTIwOTg2NGY2M2VhMmQ3N2Rj
|
14
|
+
NTYzYzQxOTRkZWI5MDJjOWU0ODE0YmU0MDc2YjEwZjMwMjJkMjY4MzBlYjAx
|
15
|
+
MWM1NzJiMDljYzhiOWNhNDllYjdlYTUxMWEwMTg3ZDEzMjY1NDY=
|
data/README.md
CHANGED
@@ -138,6 +138,35 @@ Oww, yeah, let's notify the customer
|
|
138
138
|
|
139
139
|
Let me know what do you think about it.
|
140
140
|
|
141
|
+
|
142
|
+
#### UseCase::Base contract
|
143
|
+
|
144
|
+
````
|
145
|
+
# None of those methods are required.
|
146
|
+
|
147
|
+
|
148
|
+
class BusinessRule < UseCase::Base
|
149
|
+
|
150
|
+
def before
|
151
|
+
# executed before perform
|
152
|
+
end
|
153
|
+
|
154
|
+
def perform
|
155
|
+
# execute the responsability that you want
|
156
|
+
end
|
157
|
+
|
158
|
+
def rollback
|
159
|
+
# Will be called only on failure
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
|
165
|
+
````
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
141
170
|
#### TODO
|
142
171
|
|
143
172
|
Create real case examples (40%)
|
data/lib/usecasing/context.rb
CHANGED
@@ -33,12 +33,16 @@ module UseCase
|
|
33
33
|
|
34
34
|
attr_accessor :errors
|
35
35
|
|
36
|
-
def initialize(
|
37
|
-
raise ArgumentError.new('Must be a Hash') unless
|
38
|
-
@values = symbolyze_keys(
|
36
|
+
def initialize(param = {})
|
37
|
+
raise ArgumentError.new('Must be a Hash or other Context') unless (param.is_a? ::Hash) || (param.is_a? Context)
|
38
|
+
@values = symbolyze_keys(param.to_hash)
|
39
39
|
@errors = Errors.new
|
40
40
|
end
|
41
41
|
|
42
|
+
def to_hash
|
43
|
+
@values
|
44
|
+
end
|
45
|
+
|
42
46
|
def method_missing(method, *args, &block)
|
43
47
|
return @values[extract_key_from(method)] = args.first if setter? method
|
44
48
|
@values[method]
|
data/lib/usecasing/version.rb
CHANGED
data/spec/context_spec.rb
CHANGED
@@ -79,8 +79,12 @@ describe UseCase::Context do
|
|
79
79
|
expect(@expected).to eql('<li>email</li><li>base</li>')
|
80
80
|
end
|
81
81
|
|
82
|
-
|
83
|
-
|
82
|
+
it 'returns a hash' do
|
83
|
+
context = described_class.new({})
|
84
|
+
context.name = 'thiago'
|
85
|
+
context.last_name = 'dantas'
|
86
|
+
expect(context.to_hash).to eql({ name: 'thiago' , last_name: 'dantas'})
|
87
|
+
end
|
84
88
|
|
85
89
|
end
|
86
90
|
|
data/spec/usecase_base_spec.rb
CHANGED
@@ -53,7 +53,7 @@ describe UseCase::Base do
|
|
53
53
|
AppUseCaseInstance.perform
|
54
54
|
end
|
55
55
|
|
56
|
-
it 'receives
|
56
|
+
it 'receives a hash and create a execution context' do
|
57
57
|
|
58
58
|
SendEmailUseCase = Class.new(UseCase::Base) do
|
59
59
|
def perform
|
@@ -66,11 +66,21 @@ describe UseCase::Base do
|
|
66
66
|
expect(ctx.email).to eql('thiago.teixeira.dantas@gmail.com')
|
67
67
|
end
|
68
68
|
|
69
|
-
it '
|
69
|
+
it 'raises exception when params is neither context or a hash' do
|
70
70
|
UseCaseArgumentException = Class.new(UseCase::Base)
|
71
71
|
expect{ UseCaseArgumentException.perform(Object.new) }.to raise_error(ArgumentError)
|
72
72
|
end
|
73
73
|
|
74
|
+
it 'accepts a hash' do
|
75
|
+
UseCaseArgumentHash = Class.new(UseCase::Base)
|
76
|
+
expect{ UseCaseArgumentHash.perform({}) }.not_to raise_error
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'accepts other context' do
|
80
|
+
UseCaseArgumentContext = Class.new(UseCase::Base)
|
81
|
+
expect{ UseCaseArgumentContext.perform(UseCase::Context.new) }.not_to raise_error
|
82
|
+
end
|
83
|
+
|
74
84
|
it 'with success when usecase do not register failure' do
|
75
85
|
pending
|
76
86
|
end
|