usecasing 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmM1ZGY4MDNmYWM4MTA5MTAwN2Y5N2I1MGQ3MmRlNjY1MzM0ODliYQ==
4
+ MTcyYWZhMWNjZmRmZWIyYzI0Yzc4NTY5ZDMyNzY2MWViYmI1ZmJkOA==
5
5
  data.tar.gz: !binary |-
6
- OTIzNmZjZmQ1ZjJiNGYwMGZjNzIzNTJiOTRjYTA1YWE5NWY5MzA1Nw==
6
+ M2ZlZmViZGM4MGIwMzIyOWExMmFiMjkyZGVkYjJiNzk2NTY2MDdkNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OTIxMjg4OWRmYTI1MmIzYWQ2NWNiYzQ3YTFiMmMyNjBjMmM2NzZkYmViMzcw
10
- Yjg3NWNjYjQyOWJjODhjODFlZTMxNzRkNWM5MjRlMzgzNjA3NTgzZmI1NTRm
11
- NDRiMmUyMzQ1ZTNmNjg4NTY4MzRlZGFhMWJmNjIzMGJlMDY0Nzg=
9
+ YzQzZTk4MmEzNGU4MjlkMjA5MWQ1MDRhNWQyZGE5MDc0ODdjODAzOTEwOGY0
10
+ NmJjM2EzMGQzZDZlZWYwZGRkMzJiMTdjOGE1MWU1YTBiZjZkYmM5YTNlMmEx
11
+ NmIzNmMxOGE0NGM1NWQ0MDIyYjYyMDA3ZmJhMmI3Yzk3ZTIzYjM=
12
12
  data.tar.gz: !binary |-
13
- ZmQ2OGE3MTJlMjJlNDRkZjQ0YjBmOWI0MTAzYTYzNmJhYTkxYzU0YjhhZjgz
14
- MGRhMGIxZWIxMWQwNDA4MzY5ZWJhNzZiZGI2MTM1MWZjZjViNzJhYTZjNWM3
15
- OGVlNDFhNTgwY2RiMGU4OGVjYjk0NjA1YzMyNmFlNzg0NWIwODA=
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%)
@@ -33,12 +33,16 @@ module UseCase
33
33
 
34
34
  attr_accessor :errors
35
35
 
36
- def initialize(hash = {})
37
- raise ArgumentError.new('Must be a Hash') unless hash.is_a? ::Hash
38
- @values = symbolyze_keys(hash)
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]
@@ -1,3 +1,3 @@
1
1
  module Usecasing
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
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
 
@@ -53,7 +53,7 @@ describe UseCase::Base do
53
53
  AppUseCaseInstance.perform
54
54
  end
55
55
 
56
- it 'receives receives a hash and create a execution context' do
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 'must receive an hash' do
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usecasing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thiago Dantas