u-case 3.0.0.rc2 → 3.0.0.rc7
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 +4 -4
- data/Gemfile +3 -2
- data/README.md +274 -259
- data/README.pt-BR.md +1390 -0
- data/lib/micro/case.rb +60 -33
- data/lib/micro/case/config.rb +23 -0
- data/lib/micro/case/error.rb +4 -6
- data/lib/micro/case/result.rb +89 -44
- data/lib/micro/case/safe.rb +2 -2
- data/lib/micro/case/utils.rb +7 -0
- data/lib/micro/case/version.rb +1 -1
- data/lib/micro/case/with_activemodel_validation.rb +3 -1
- data/lib/micro/cases/flow.rb +24 -40
- data/lib/micro/cases/safe/flow.rb +2 -2
- data/lib/u-case/with_activemodel_validation.rb +0 -2
- data/u-case.gemspec +2 -2
- metadata +6 -4
data/lib/micro/case/safe.rb
CHANGED
data/lib/micro/case/utils.rb
CHANGED
data/lib/micro/case/version.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'kind/active_model/validation'
|
4
|
+
|
3
5
|
require 'micro/case'
|
4
6
|
|
5
7
|
module Micro
|
@@ -29,7 +31,7 @@ module Micro
|
|
29
31
|
|
30
32
|
return result if result.is_a?(Result)
|
31
33
|
|
32
|
-
raise Error::UnexpectedResult.new(self.class)
|
34
|
+
raise Error::UnexpectedResult.new("#{self.class.name}#call!")
|
33
35
|
end
|
34
36
|
|
35
37
|
def failure_by_validation_error(object)
|
data/lib/micro/cases/flow.rb
CHANGED
@@ -29,66 +29,50 @@ module Micro
|
|
29
29
|
@next_use_cases = use_cases[1..-1]
|
30
30
|
end
|
31
31
|
|
32
|
-
def call(
|
33
|
-
|
34
|
-
|
35
|
-
first_result = first_use_case_result(arg)
|
32
|
+
def call!(input:, result:)
|
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
|
-
|
37
|
+
__next_use_cases_result(first_result)
|
40
38
|
end
|
41
39
|
|
42
|
-
def
|
43
|
-
|
40
|
+
def call(input = Kind::Empty::HASH)
|
41
|
+
call!(input: input, result: Case::Result.new)
|
44
42
|
end
|
45
43
|
|
46
|
-
|
44
|
+
alias __call__ call
|
47
45
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
def arg_to_call?(arg)
|
53
|
-
return true if arg.is_a?(::Micro::Case) || arg.is_a?(Flow)
|
54
|
-
return true if arg.is_a?(Class) && arg < ::Micro::Case
|
55
|
-
return false
|
56
|
-
end
|
46
|
+
def to_proc
|
47
|
+
Proc.new { |arg| call(arg) }
|
48
|
+
end
|
57
49
|
|
58
|
-
|
59
|
-
|
50
|
+
def then(use_case = nil, &block)
|
51
|
+
can_yield_self = respond_to?(:yield_self)
|
60
52
|
|
61
|
-
|
62
|
-
|
53
|
+
if block
|
54
|
+
raise Error::InvalidInvocationOfTheThenMethod if use_case
|
55
|
+
raise NotImplementedError if !can_yield_self
|
63
56
|
|
64
|
-
|
65
|
-
|
66
|
-
return
|
57
|
+
yield_self(&block)
|
58
|
+
else
|
59
|
+
return yield_self if !use_case && can_yield_self
|
67
60
|
|
68
|
-
|
61
|
+
self.call.then(use_case)
|
69
62
|
end
|
63
|
+
end
|
70
64
|
|
71
|
-
|
72
|
-
input = first_use_case_input(arg)
|
73
|
-
|
74
|
-
result = Case::Result.new
|
75
|
-
|
76
|
-
@first_use_case.__call_and_set_transition__(result, input)
|
77
|
-
end
|
65
|
+
private
|
78
66
|
|
79
|
-
def
|
80
|
-
use_case.__new__(result, input).
|
67
|
+
def __next_use_case_result(use_case, result, input)
|
68
|
+
use_case.__new__(result, input).__call__
|
81
69
|
end
|
82
70
|
|
83
|
-
def
|
71
|
+
def __next_use_cases_result(first_result)
|
84
72
|
@next_use_cases.reduce(first_result) do |result, use_case|
|
85
73
|
break result if result.failure?
|
86
74
|
|
87
|
-
|
88
|
-
|
89
|
-
result.__set_transitions_accessible_attributes__(memo)
|
90
|
-
|
91
|
-
next_use_case_result(use_case, result, memo)
|
75
|
+
__next_use_case_result(use_case, result, result.data)
|
92
76
|
end
|
93
77
|
end
|
94
78
|
end
|
@@ -4,9 +4,9 @@ module Micro
|
|
4
4
|
module Cases
|
5
5
|
module Safe
|
6
6
|
class Flow < Cases::Flow
|
7
|
-
private def
|
7
|
+
private def __next_use_case_result(use_case, result, input)
|
8
8
|
instance = use_case.__new__(result, input)
|
9
|
-
instance.
|
9
|
+
instance.__call__
|
10
10
|
rescue => exception
|
11
11
|
raise exception if Case::Error.by_wrong_usage?(exception)
|
12
12
|
|
data/u-case.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ['Rodrigo Serradura']
|
10
10
|
spec.email = ['rodrigo.serradura@gmail.com']
|
11
11
|
|
12
|
-
spec.summary = %q{Create simple and powerful use cases as objects.}
|
13
|
-
spec.description = %q{Create simple and powerful use cases as objects.}
|
12
|
+
spec.summary = %q{Create simple and powerful use cases as Ruby objects.}
|
13
|
+
spec.description = %q{Create simple and powerful use cases as Ruby objects.}
|
14
14
|
spec.homepage = 'https://github.com/serradura/u-case'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
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.
|
4
|
+
version: 3.0.0.rc7
|
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-
|
11
|
+
date: 2020-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kind
|
@@ -72,7 +72,7 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '13.0'
|
75
|
-
description: Create simple and powerful use cases as objects.
|
75
|
+
description: Create simple and powerful use cases as Ruby objects.
|
76
76
|
email:
|
77
77
|
- rodrigo.serradura@gmail.com
|
78
78
|
executables: []
|
@@ -87,10 +87,12 @@ files:
|
|
87
87
|
- Gemfile
|
88
88
|
- LICENSE.txt
|
89
89
|
- README.md
|
90
|
+
- README.pt-BR.md
|
90
91
|
- Rakefile
|
91
92
|
- bin/console
|
92
93
|
- bin/setup
|
93
94
|
- lib/micro/case.rb
|
95
|
+
- lib/micro/case/config.rb
|
94
96
|
- lib/micro/case/error.rb
|
95
97
|
- lib/micro/case/result.rb
|
96
98
|
- lib/micro/case/safe.rb
|
@@ -127,5 +129,5 @@ requirements: []
|
|
127
129
|
rubygems_version: 3.0.6
|
128
130
|
signing_key:
|
129
131
|
specification_version: 4
|
130
|
-
summary: Create simple and powerful use cases as objects.
|
132
|
+
summary: Create simple and powerful use cases as Ruby objects.
|
131
133
|
test_files: []
|