u-case 3.0.0.rc5 → 3.0.0.rc6

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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12b63a467f7516217f29a5705859141be80fc2fb2209c41e77d7c8a365745b8c
4
- data.tar.gz: 4501314217a04cca7d56c0091a8a2c02f93f308f51c323462af36c71532be1b3
3
+ metadata.gz: 1a1e5c36bfc65522732f2e00f8b57a2fe84bbe59a730cb85287f56de7850dea0
4
+ data.tar.gz: 22bf46677b24e2f8fb6f3b060ba6bc348a7a8025556d1f3cf6ddf81d0e204279
5
5
  SHA512:
6
- metadata.gz: 85351b75b4e2e2e62e66f2dff078a607ffa29e5c0df93dc3f6ce07dbfd0444ecd3034358fc08b358698c7ca2ccd73dbc5b8ab597ce339c5d7f4970df504b8a99
7
- data.tar.gz: 5ef5552ca31fc9d9474f9a54717c7ce9a45ad9aba46710bf6671ae5836a492981beb4bee3cbdfbb5418770bcd896a634846eb659b5eaf1c098d6fa0c9339dc7b
6
+ metadata.gz: a6276a81c7e006d07922b2b30de0a066e1a9a2bc0856586287a35263e21f9c353d571fbf666a08348988c6f42ea893730008e77ea42f65867c801aa24bf19299
7
+ data.tar.gz: 47e3482b444c3b9730a3cc5e37ca78bc26556454c1155045663e9b1c597203fc11584dbc7e6716fefaf093cfb8dbcd5f7db63b84b04d8bd5598e94b00c2dfb7c
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ![Ruby](https://img.shields.io/badge/ruby-2.2+-ruby.svg?colorA=99004d&colorB=cc0066)
2
2
  [![Gem](https://img.shields.io/gem/v/u-case.svg?style=flat-square)](https://rubygems.org/gems/u-case)
3
- [![Build Status](https://travis-ci.com/serradura/u-case.svg?branch=master)](https://travis-ci.com/serradura/u-case)
3
+ [![Build Status](https://travis-ci.com/serradura/u-case.svg?branch=main)](https://travis-ci.com/serradura/u-case)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/5c3c8ad1b0b943f88efd/maintainability)](https://codeclimate.com/github/serradura/u-case/maintainability)
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/5c3c8ad1b0b943f88efd/test_coverage)](https://codeclimate.com/github/serradura/u-case/test_coverage)
6
6
 
@@ -21,7 +21,7 @@ The main project goals are:
21
21
 
22
22
  Version | Documentation
23
23
  --------- | -------------
24
- 3.0.0.rc5 | https://github.com/serradura/u-case/blob/master/README.md
24
+ 3.0.0.rc5 | https://github.com/serradura/u-case/blob/main/README.md
25
25
  2.6.0 | https://github.com/serradura/u-case/blob/v2.x/README.md
26
26
  1.1.0 | https://github.com/serradura/u-case/blob/v1.x/README.md
27
27
 
@@ -1215,7 +1215,7 @@ end
1215
1215
  ```
1216
1216
  </details>
1217
1217
 
1218
- https://github.com/serradura/u-case/blob/master/benchmarks/use_case/with_success_result.rb
1218
+ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_success_result.rb
1219
1219
 
1220
1220
  #### Failure results
1221
1221
 
@@ -1260,13 +1260,13 @@ https://github.com/serradura/u-case/blob/master/benchmarks/use_case/with_success
1260
1260
  ```
1261
1261
  </details>
1262
1262
 
1263
- https://github.com/serradura/u-case/blob/master/benchmarks/use_case/with_failure_result.rb
1263
+ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_failure_result.rb
1264
1264
 
1265
1265
  ---
1266
1266
 
1267
1267
  ### `Micro::Cases::Flow` (v3.0.0)
1268
1268
 
1269
- | Gems / Abstraction | [Success results](https://github.com/serradura/u-case/blob/master/benchmarks/flow/with_success_result.rb#L40) | [Failure results](https://github.com/serradura/u-case/blob/master/benchmarks/flow/with_failure_result.rb#L40) |
1269
+ | Gems / Abstraction | [Success results](https://github.com/serradura/u-case/blob/main/benchmarks/flow/with_success_result.rb#L40) | [Failure results](https://github.com/serradura/u-case/blob/main/benchmarks/flow/with_failure_result.rb#L40) |
1270
1270
  | ------------------------------------------- | ----------------: | ----------------: |
1271
1271
  | Micro::Case internal flow (private methods) | _**The Fastest**_ | _**The Fastest**_ |
1272
1272
  | Micro::Case `then` method | 1.48x slower | 0x slower |
@@ -1330,14 +1330,14 @@ https://github.com/serradura/u-case/blob/master/benchmarks/use_case/with_failure
1330
1330
  ```
1331
1331
  </details>
1332
1332
 
1333
- https://github.com/serradura/u-case/tree/master/benchmarks/flow
1333
+ https://github.com/serradura/u-case/tree/main/benchmarks/flow
1334
1334
 
1335
1335
  ### Comparisons
1336
1336
 
1337
1337
  Check it out implementations of the same use case with different gems/abstractions.
1338
1338
 
1339
- * [interactor](https://github.com/serradura/u-case/blob/master/comparisons/interactor.rb)
1340
- * [u-case](https://github.com/serradura/u-case/blob/master/comparisons/u-case.rb)
1339
+ * [interactor](https://github.com/serradura/u-case/blob/main/comparisons/interactor.rb)
1340
+ * [u-case](https://github.com/serradura/u-case/blob/main/comparisons/u-case.rb)
1341
1341
 
1342
1342
  [⬆️ Back to Top](#table-of-contents-)
1343
1343
 
@@ -1353,17 +1353,17 @@ Check it out implementations of the same use case with different gems/abstractio
1353
1353
 
1354
1354
  > Rake tasks to demonstrate how to handle user data, and how to use different failure types to control the program flow.
1355
1355
  >
1356
- > Link: https://github.com/serradura/u-case/tree/master/examples/calculator
1356
+ > Link: https://github.com/serradura/u-case/tree/main/examples/calculator
1357
1357
 
1358
1358
  ### 3️⃣ Users creation
1359
1359
 
1360
1360
  > An example of a use case flow that defines steps to sanitize, validate, and persist its input data.
1361
1361
  >
1362
- > Link: https://github.com/serradura/u-case/blob/master/examples/users_creation.rb
1362
+ > Link: https://github.com/serradura/u-case/blob/main/examples/users_creation.rb
1363
1363
 
1364
1364
  ### 4️⃣ Rescuing exceptions inside of the use cases
1365
1365
 
1366
- > Link: https://github.com/serradura/u-case/blob/master/examples/rescuing_exceptions.rb
1366
+ > Link: https://github.com/serradura/u-case/blob/main/examples/rescuing_exceptions.rb
1367
1367
 
1368
1368
  [⬆️ Back to Top](#table-of-contents-)
1369
1369
 
@@ -1383,4 +1383,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
1383
1383
 
1384
1384
  ## Code of Conduct
1385
1385
 
1386
- Everyone interacting in the Micro::Case project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/serradura/u-case/blob/master/CODE_OF_CONDUCT.md).
1386
+ Everyone interacting in the Micro::Case project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/serradura/u-case/blob/main/CODE_OF_CONDUCT.md).
@@ -1,6 +1,6 @@
1
1
  ![Ruby](https://img.shields.io/badge/ruby-2.2+-ruby.svg?colorA=99004d&colorB=cc0066)
2
2
  [![Gem](https://img.shields.io/gem/v/u-case.svg?style=flat-square)](https://rubygems.org/gems/u-case)
3
- [![Build Status](https://travis-ci.com/serradura/u-case.svg?branch=master)](https://travis-ci.com/serradura/u-case)
3
+ [![Build Status](https://travis-ci.com/serradura/u-case.svg?branch=main)](https://travis-ci.com/serradura/u-case)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/5c3c8ad1b0b943f88efd/maintainability)](https://codeclimate.com/github/serradura/u-case/maintainability)
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/5c3c8ad1b0b943f88efd/test_coverage)](https://codeclimate.com/github/serradura/u-case/test_coverage)
6
6
 
@@ -21,7 +21,7 @@ Principais objetivos deste projeto:
21
21
 
22
22
  Versão | Documentação
23
23
  --------- | -------------
24
- 3.0.0.rc5 | https://github.com/serradura/u-case/blob/master/README.md
24
+ 3.0.0.rc5 | https://github.com/serradura/u-case/blob/main/README.md
25
25
  2.6.0 | https://github.com/serradura/u-case/blob/v2.x/README.md
26
26
  1.1.0 | https://github.com/serradura/u-case/blob/v1.x/README.md
27
27
 
@@ -1219,7 +1219,7 @@ end
1219
1219
  ```
1220
1220
  </details>
1221
1221
 
1222
- https://github.com/serradura/u-case/blob/master/benchmarks/use_case/with_success_result.rb
1222
+ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_success_result.rb
1223
1223
 
1224
1224
  #### Failure results
1225
1225
 
@@ -1264,13 +1264,13 @@ https://github.com/serradura/u-case/blob/master/benchmarks/use_case/with_success
1264
1264
  ```
1265
1265
  </details>
1266
1266
 
1267
- https://github.com/serradura/u-case/blob/master/benchmarks/use_case/with_failure_result.rb
1267
+ https://github.com/serradura/u-case/blob/main/benchmarks/use_case/with_failure_result.rb
1268
1268
 
1269
1269
  ---
1270
1270
 
1271
1271
  ### `Micro::Cases::Flow` (v3.0.0)
1272
1272
 
1273
- | Gem / Abstração | [Resultados de sucesso](https://github.com/serradura/u-case/blob/master/benchmarks/flow/with_success_result.rb#L40) | [Resultados de falha](https://github.com/serradura/u-case/blob/master/benchmarks/flow/with_failure_result.rb#L40) |
1273
+ | Gem / Abstração | [Resultados de sucesso](https://github.com/serradura/u-case/blob/main/benchmarks/flow/with_success_result.rb#L40) | [Resultados de falha](https://github.com/serradura/u-case/blob/main/benchmarks/flow/with_failure_result.rb#L40) |
1274
1274
  | ------------------------------------------- | ----------------: | ----------------: |
1275
1275
  | Micro::Case internal flow (private methods) | _**O mais rápido**_ | _**O mais rápido**_ |
1276
1276
  | Micro::Case `then` method | 1.48x slower | 0x slower |
@@ -1334,14 +1334,14 @@ https://github.com/serradura/u-case/blob/master/benchmarks/use_case/with_failure
1334
1334
  ```
1335
1335
  </details>
1336
1336
 
1337
- https://github.com/serradura/u-case/tree/master/benchmarks/flow
1337
+ https://github.com/serradura/u-case/tree/main/benchmarks/flow
1338
1338
 
1339
1339
  ### Comparações
1340
1340
 
1341
1341
  Confira as implementações do mesmo caso de uso com diferentes gems/abstrações.
1342
1342
 
1343
- * [interactor](https://github.com/serradura/u-case/blob/master/comparisons/interactor.rb)
1344
- * [u-case](https://github.com/serradura/u-case/blob/master/comparisons/u-case.rb)
1343
+ * [interactor](https://github.com/serradura/u-case/blob/main/comparisons/interactor.rb)
1344
+ * [u-case](https://github.com/serradura/u-case/blob/main/comparisons/u-case.rb)
1345
1345
 
1346
1346
  [⬆️ Voltar para o índice](#índice-)
1347
1347
 
@@ -1357,17 +1357,17 @@ Confira as implementações do mesmo caso de uso com diferentes gems/abstraçõe
1357
1357
 
1358
1358
  > Rake tasks para demonstrar como lidar com os dados do usuário e como usar diferentes tipos de falha para controlar o fluxo do programa.
1359
1359
  >
1360
- > Link: https://github.com/serradura/u-case/tree/master/examples/calculator
1360
+ > Link: https://github.com/serradura/u-case/tree/main/examples/calculator
1361
1361
 
1362
1362
  ### 3️⃣ Criação de usuários
1363
1363
 
1364
1364
  > Um exemplo de fluxo de caso de uso que define etapas para higienizar, validar e persistir seus dados de entrada.
1365
1365
  >
1366
- > Link: https://github.com/serradura/u-case/blob/master/examples/users_creation.rb
1366
+ > Link: https://github.com/serradura/u-case/blob/main/examples/users_creation.rb
1367
1367
 
1368
1368
  ### 4️⃣ Interceptando exceções dentro dos casos de uso
1369
1369
 
1370
- > Link: https://github.com/serradura/u-case/blob/master/examples/rescuing_exceptions.rb
1370
+ > Link: https://github.com/serradura/u-case/blob/main/examples/rescuing_exceptions.rb
1371
1371
 
1372
1372
  [⬆️ Voltar para o índice](#índice-)
1373
1373
 
@@ -1387,4 +1387,4 @@ A gem está disponível como código aberto nos termos da [licença MIT](https:/
1387
1387
 
1388
1388
  ## Código de conduta
1389
1389
 
1390
- Espera-se que todos que interagem com o codebase do projeto `Micro::Case`, issue trackers, chat rooms and mailing lists sigam o [código de conduta](https://github.com/serradura/u-case/blob/master/CODE_OF_CONDUCT.md).
1390
+ Espera-se que todos que interagem com o codebase do projeto `Micro::Case`, issue trackers, chat rooms and mailing lists sigam o [código de conduta](https://github.com/serradura/u-case/blob/main/CODE_OF_CONDUCT.md).
@@ -70,18 +70,13 @@ module Micro
70
70
  end
71
71
 
72
72
  def self.__new__(result, arg)
73
- instance = new(arg)
73
+ input = result.__set_transitions_accessible_attributes__(arg)
74
+
75
+ instance = new(input)
74
76
  instance.__set_result__(result)
75
77
  instance
76
78
  end
77
79
 
78
- def self.__call_and_set_transition__(result, arg)
79
- input =
80
- arg.is_a?(Hash) ? result.__set_transitions_accessible_attributes__(arg) : arg
81
-
82
- __new__(result, input).__call__
83
- end
84
-
85
80
  def self.__flow_builder__
86
81
  Cases::Flow
87
82
  end
@@ -15,7 +15,7 @@ module Micro
15
15
 
16
16
  def enable_transitions=(value)
17
17
  Micro::Case::Result.class_variable_set(
18
- :@@transition_tracking_disabled, !Kind::Of::Boolean(value)
18
+ :@@transition_tracking_enabled, Kind::Of::Boolean(value)
19
19
  )
20
20
  end
21
21
  end
@@ -7,15 +7,16 @@ module Micro
7
7
  class Result
8
8
  Kind::Types.add(self)
9
9
 
10
- @@transition_tracking_disabled = false
10
+ @@transition_tracking_enabled = true
11
11
 
12
12
  attr_reader :type, :data, :use_case
13
13
 
14
14
  alias value data
15
15
 
16
16
  def initialize
17
- @__transitions__ = []
18
- @__transitions_accessible_attributes__ = {}
17
+ @__transitions = []
18
+ @__transitions_accumulated_data = {}
19
+ @__transitions_accessible_attributes = {}
19
20
  end
20
21
 
21
22
  def to_ary
@@ -90,10 +91,8 @@ module Micro
90
91
  yield_self(&block)
91
92
  else
92
93
  return yield_self if !use_case && can_yield_self
93
-
94
- if use_case.is_a?(Proc)
95
- return failure? ? self : __call_proc(use_case, expected: 'then(-> {})'.freeze)
96
- end
94
+ return failure? ? self : __call_proc(use_case, 'then(-> {})'.freeze) if use_case.is_a?(Proc)
95
+ return failure? ? self : __call_method(use_case, attributes) if use_case.is_a?(Method)
97
96
 
98
97
  raise Error::InvalidInvocationOfTheThenMethod unless ::Micro.case_or_flow?(use_case)
99
98
 
@@ -104,7 +103,7 @@ module Micro
104
103
  if use_case.is_a?(::Micro::Cases::Flow)
105
104
  use_case.call!(input: input, result: self)
106
105
  else
107
- use_case.__call_and_set_transition__(self, input)
106
+ use_case.__new__(self, input).__call__
108
107
  end
109
108
  end
110
109
  end
@@ -112,15 +111,16 @@ module Micro
112
111
  def |(arg)
113
112
  return self if failure?
114
113
 
115
- return __call_proc(arg, expected: '| -> {}'.freeze) if arg.is_a?(Proc)
114
+ return __call_proc(arg, '| -> {}'.freeze) if arg.is_a?(Proc)
115
+ return __call_method(arg) if arg.is_a?(Method)
116
116
 
117
117
  raise Error::InvalidInvocationOfTheThenMethod unless ::Micro.case_or_flow?(arg)
118
118
 
119
- failure? ? self : arg.__call_and_set_transition__(self, data)
119
+ failure? ? self : arg.__new__(self, data).__call__
120
120
  end
121
121
 
122
122
  def transitions
123
- @__transitions__.clone
123
+ @__transitions.clone
124
124
  end
125
125
 
126
126
  FetchData = -> (data) do
@@ -140,29 +140,52 @@ module Micro
140
140
 
141
141
  raise Micro::Case::Error::InvalidResult.new(is_success, type, use_case) unless @data
142
142
 
143
- __set_transition unless @@transition_tracking_disabled
143
+ if @@transition_tracking_enabled
144
+ @__transitions_accumulated_data.merge!(@data)
145
+
146
+ __set_transition
147
+ end
144
148
 
145
149
  self
146
150
  end
147
151
 
148
- def __set_transitions_accessible_attributes__(attributes_data)
149
- return attributes_data if @@transition_tracking_disabled
152
+ def __set_transitions_accessible_attributes__(arg)
153
+ return arg unless @@transition_tracking_enabled
150
154
 
151
- attributes = Utils.symbolize_hash_keys(attributes_data)
155
+ if arg.is_a?(Hash)
156
+ attributes = Utils.symbolize_hash_keys(arg)
152
157
 
153
- __update_transitions_accessible_attributes(attributes)
158
+ __update_transitions_accessible_attributes(attributes)
159
+ end
154
160
  end
155
161
 
156
162
  private
157
163
 
158
- def __call_proc(arg, expected:)
159
- result = arg.arity.zero? ? arg.call : arg.call(data.clone)
164
+ def __call_with_accumulated_data(fn, opt = nil)
165
+ input =
166
+ __update_transitions_accessible_attributes(
167
+ opt ? opt.merge(@__transitions_accumulated_data) : @__transitions_accumulated_data
168
+ )
169
+
170
+ fn.arity.zero? ? fn.call : fn.call(input)
171
+ end
172
+
173
+ def __call_proc(fn, expected)
174
+ result = __call_with_accumulated_data(fn)
160
175
 
161
- return result if result.is_a?(Result)
176
+ return self if result === self
162
177
 
163
178
  raise Error::UnexpectedResult.new("#{Result.name}##{expected}")
164
179
  end
165
180
 
181
+ def __call_method(methd, attributes = nil)
182
+ result = __call_with_accumulated_data(methd, attributes)
183
+
184
+ return self if result === self
185
+
186
+ raise Error::UnexpectedResult.new("#{use_case.class.name}#method(:#{methd.name})")
187
+ end
188
+
166
189
  def __success_type?(expected_type)
167
190
  success? && (expected_type.nil? || expected_type == type)
168
191
  end
@@ -172,8 +195,8 @@ module Micro
172
195
  end
173
196
 
174
197
  def __update_transitions_accessible_attributes(attributes)
175
- @__transitions_accessible_attributes__.merge!(attributes)
176
- @__transitions_accessible_attributes__
198
+ @__transitions_accessible_attributes.merge!(attributes)
199
+ @__transitions_accessible_attributes
177
200
  end
178
201
 
179
202
  def __set_transition
@@ -184,10 +207,10 @@ module Micro
184
207
 
185
208
  result = @success ? :success : :failure
186
209
 
187
- @__transitions__ << {
210
+ @__transitions << {
188
211
  use_case: { class: use_case_class, attributes: use_case_attributes },
189
212
  result => { type: @type, result: data },
190
- accessible_attributes: @__transitions_accessible_attributes__.keys
213
+ accessible_attributes: @__transitions_accessible_attributes.keys
191
214
  }
192
215
  end
193
216
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Micro
4
4
  class Case
5
- VERSION = '3.0.0.rc5'.freeze
5
+ VERSION = '3.0.0.rc6'.freeze
6
6
  end
7
7
  end
@@ -30,13 +30,11 @@ module Micro
30
30
  end
31
31
 
32
32
  def call!(input:, result:)
33
- memo = input.is_a?(Hash) ? input.dup : Kind::Empty::HASH
34
-
35
- first_result = @first_use_case.__call_and_set_transition__(result, input)
33
+ first_result = __next_use_case_result(@first_use_case, result, input)
36
34
 
37
35
  return first_result if @next_use_cases.empty?
38
36
 
39
- __next_use_cases_result(first_result, memo)
37
+ __next_use_cases_result(first_result)
40
38
  end
41
39
 
42
40
  def call(input = Kind::Empty::HASH)
@@ -70,15 +68,11 @@ module Micro
70
68
  use_case.__new__(result, input).__call__
71
69
  end
72
70
 
73
- def __next_use_cases_result(first_result, memo)
71
+ def __next_use_cases_result(first_result)
74
72
  @next_use_cases.reduce(first_result) do |result, use_case|
75
73
  break result if result.failure?
76
74
 
77
- memo.merge!(result.value)
78
-
79
- result.__set_transitions_accessible_attributes__(memo)
80
-
81
- __next_use_case_result(use_case, result, memo)
75
+ __next_use_case_result(use_case, result, result.data)
82
76
  end
83
77
  end
84
78
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: u-case
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.rc5
4
+ version: 3.0.0.rc6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Serradura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-12 00:00:00.000000000 Z
11
+ date: 2020-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kind