u-case 2.0.0.pre.3 → 2.0.0.pre.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -2
- data/lib/micro/case/flow/reducer.rb +10 -1
- data/lib/micro/case/safe/flow.rb +2 -10
- data/lib/micro/case/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7108e24cbd9380af05232f2fa160a1131cb0fc3a717faf44a157ad577a5e1d70
|
4
|
+
data.tar.gz: e2ca33aea49622868611af975e31a39d987c52401f8e3efccce0bbc1940395c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da0de298a0a3f889c13244fd60095ab6268dd35eab881aa8e10c35c3fb2c051670dc2563aef3c52e23366adba9554f31822f565c0a892fc9e0c69363f7c07c94
|
7
|
+
data.tar.gz: 73b1fbaec0d6e15adb5d714491081bbf592920757b134139021ad7058e42c5eefa8ab420b7215442fcf9777ecc338cac0e4fa3b4dd8b833f4eb00fb70e1f9ab7
|
data/README.md
CHANGED
@@ -30,6 +30,7 @@ The main goals of this project are:
|
|
30
30
|
- [What happens if a result hook is declared multiple times?](#what-happens-if-a-result-hook-is-declared-multiple-times)
|
31
31
|
- [How to compose uses cases to represents complex ones?](#how-to-compose-uses-cases-to-represents-complex-ones)
|
32
32
|
- [Is it possible to compose a use case flow with other ones?](#is-it-possible-to-compose-a-use-case-flow-with-other-ones)
|
33
|
+
- [Is it possible a flow accumulates its input and merges each success result to use as the argument of their use cases?](#is-it-possible-a-flow-accumulates-its-input-and-merges-each-success-result-to-use-as-the-argument-of-their-use-cases)
|
33
34
|
- [What is a strict use case?](#what-is-a-strict-use-case)
|
34
35
|
- [Is there some feature to auto handle exceptions inside of a use case or flow?](#is-there-some-feature-to-auto-handle-exceptions-inside-of-a-use-case-or-flow)
|
35
36
|
- [How to validate use case attributes?](#how-to-validate-use-case-attributes)
|
@@ -318,7 +319,7 @@ class Double < Micro::Case
|
|
318
319
|
|
319
320
|
def call!
|
320
321
|
return Failure(:invalid) unless number.is_a?(Numeric)
|
321
|
-
return Failure(:lte_zero) if number <= 0
|
322
|
+
return Failure(:lte_zero) { number } if number <= 0
|
322
323
|
|
323
324
|
Success(number * 2)
|
324
325
|
end
|
@@ -404,7 +405,8 @@ result.value * 4 == accum # true
|
|
404
405
|
|
405
406
|
### How to compose uses cases to represents complex ones?
|
406
407
|
|
407
|
-
In this case, this will be a **flow
|
408
|
+
In this case, this will be a **flow** (`Micro::Case::Flow`).
|
409
|
+
The main idea of this feature is to use/reuse use cases as steps of a new use case.
|
408
410
|
|
409
411
|
```ruby
|
410
412
|
module Steps
|
@@ -567,6 +569,10 @@ Note: You can blend any of the [available syntaxes/approaches](#how-to-create-a-
|
|
567
569
|
|
568
570
|
[⬆️ Back to Top](#table-of-contents-)
|
569
571
|
|
572
|
+
#### Is it possible a flow accumulates its input and merges each success result to use as the argument of their use cases?
|
573
|
+
|
574
|
+
Answer: Yes, it is! Check out these test examples [Micro::Case::Flow](https://github.com/serradura/u-case/blob/e0066d8a6e3a9404069dfcb9bf049b854f08a33c/test/micro/case/flow/reducer_test.rb) and [Micro::Case::Safe::Flow](https://github.com/serradura/u-case/blob/e0066d8a6e3a9404069dfcb9bf049b854f08a33c/test/micro/case/safe/flow/reducer_test.rb) to see different use cases sharing their own data.
|
575
|
+
|
570
576
|
### What is a strict use case?
|
571
577
|
|
572
578
|
Answer: Is a use case which will require all the keywords (attributes) on its initialization.
|
@@ -26,10 +26,15 @@ module Micro
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def call(arg = {})
|
29
|
+
memo = arg.is_a?(Hash) ? arg.dup : {}
|
30
|
+
|
29
31
|
@use_cases.reduce(initial_result(arg)) do |result, use_case|
|
30
32
|
break result if result.failure?
|
31
33
|
|
32
|
-
|
34
|
+
value = result.value
|
35
|
+
input = value.is_a?(Hash) ? memo.tap { |data| data.merge!(value) } : value
|
36
|
+
|
37
|
+
use_case_result(use_case, result, input)
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
@@ -47,6 +52,10 @@ module Micro
|
|
47
52
|
|
48
53
|
private
|
49
54
|
|
55
|
+
def use_case_result(use_case, result, input)
|
56
|
+
use_case.__new__(result, input).call
|
57
|
+
end
|
58
|
+
|
50
59
|
def initial_result(arg)
|
51
60
|
return arg.call if arg_to_call?(arg)
|
52
61
|
return arg if arg.is_a?(Micro::Case::Result)
|
data/lib/micro/case/safe/flow.rb
CHANGED
@@ -11,14 +11,6 @@ module Micro
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class Reducer < ::Micro::Case::Flow::Reducer
|
14
|
-
def call(arg = {})
|
15
|
-
@use_cases.reduce(initial_result(arg)) do |result, use_case|
|
16
|
-
break result if result.failure?
|
17
|
-
|
18
|
-
use_case_result(use_case, result)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
14
|
alias_method :&, :>>
|
23
15
|
|
24
16
|
def >>(arg)
|
@@ -27,9 +19,9 @@ module Micro
|
|
27
19
|
|
28
20
|
private
|
29
21
|
|
30
|
-
def use_case_result(use_case, result)
|
22
|
+
def use_case_result(use_case, result, input)
|
31
23
|
begin
|
32
|
-
instance = use_case.__new__(result,
|
24
|
+
instance = use_case.__new__(result, input)
|
33
25
|
instance.call
|
34
26
|
rescue => exception
|
35
27
|
raise exception if Error::ByWrongUsage.check(exception)
|
data/lib/micro/case/version.rb
CHANGED
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: 2.0.0.pre.
|
4
|
+
version: 2.0.0.pre.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Serradura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: u-attributes
|