u-case 3.0.0.rc1 → 3.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -9
- data/lib/micro/case/error.rb +14 -11
- data/lib/micro/case/result.rb +5 -6
- data/lib/micro/case/version.rb +1 -1
- data/u-case.gemspec +1 -1
- metadata +10 -5
- data/lib/u-case/with_validation.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfc46204c461937d19681ae26dca7846a8d36720b735d759023b4c1369ef2a9a
|
4
|
+
data.tar.gz: 21bfd7bc9d2c2a13c901672eac77f15da4b7975aeeea925b3f94ff7e36dd1161
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e6992400490ef920d9ad855ebf698174ee2fcf9ab555db880ab2dea065360b921af7e38e4be5eb74e28c484862a25ca476beba9e2daebbc668bae07ef1b1853
|
7
|
+
data.tar.gz: d081ddf7bf5b3209f31c385060fd8dbbc9f72a8b1a05e553b1666df2f2de1550859017e9aa85aa329118bdef965f390a1637348c2a7549139e462e3cb091c250
|
data/README.md
CHANGED
@@ -20,11 +20,11 @@ The main project goals are:
|
|
20
20
|
|
21
21
|
## Documentation <!-- omit in toc -->
|
22
22
|
|
23
|
-
Version
|
24
|
-
|
25
|
-
|
26
|
-
2.6.0
|
27
|
-
1.1.0
|
23
|
+
Version | Documentation
|
24
|
+
--------- | -------------
|
25
|
+
3.0.0.rc2 | https://github.com/serradura/u-case/blob/master/README.md
|
26
|
+
2.6.0 | https://github.com/serradura/u-case/blob/v2.x/README.md
|
27
|
+
1.1.0 | https://github.com/serradura/u-case/blob/v1.x/README.md
|
28
28
|
|
29
29
|
## Table of Contents <!-- omit in toc -->
|
30
30
|
- [Required Ruby version](#required-ruby-version)
|
@@ -82,7 +82,7 @@ Unreleased | https://github.com/serradura/u-case/blob/master/README.md
|
|
82
82
|
|
83
83
|
A simple type system (at runtime) for Ruby.
|
84
84
|
|
85
|
-
Used to validate method inputs
|
85
|
+
Used to validate method inputs using its [`activemodel validation`](https://github.com/serradura/kind#kindvalidator-activemodelvalidations) module is auto required by [`u-case/with_activemodel_validation`](#u-casewith_activemodel_validation---how-to-validate-use-case-attributes) mode, and expose `Kind::Of::Micro::Case`, `Kind::Of::Micro::Case::Result` type checkers.
|
86
86
|
2. [`u-attributes`](https://github.com/serradura/u-attributes) gem.
|
87
87
|
|
88
88
|
This gem allows defining read-only attributes, that is, your objects will have only getters to access their attributes data.
|
@@ -508,9 +508,11 @@ class Add < Micro::Case
|
|
508
508
|
attributes :a, :b
|
509
509
|
|
510
510
|
def call!
|
511
|
-
|
512
|
-
|
513
|
-
|
511
|
+
if Kind.of?(Numeric, a, b)
|
512
|
+
Success result: { sum: a + b }
|
513
|
+
else
|
514
|
+
Failure(:attributes_arent_numbers)
|
515
|
+
end
|
514
516
|
end
|
515
517
|
end
|
516
518
|
|
data/lib/micro/case/error.rb
CHANGED
@@ -17,18 +17,21 @@ module Micro
|
|
17
17
|
def initialize; super('type must be a Symbol'.freeze); end
|
18
18
|
end
|
19
19
|
|
20
|
-
class
|
21
|
-
|
20
|
+
class InvalidResult < TypeError
|
21
|
+
def initialize(is_success, type, use_case)
|
22
|
+
base =
|
23
|
+
"The result returned from #{use_case.class.name}#call! must be a Hash."
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
result = is_success ? 'Success'.freeze : 'Failure'.freeze
|
26
|
+
|
27
|
+
example =
|
28
|
+
if type === :ok || type === :error || type === :exception
|
29
|
+
"#{result}(result: { key: 'value' })"
|
30
|
+
else
|
31
|
+
"#{result}(:#{type}, result: { key: 'value' })"
|
32
|
+
end
|
28
33
|
|
29
|
-
|
30
|
-
def initialize(object)
|
31
|
-
super("Failure(result: #{object.inspect}) must be a Hash, Symbol or an Exception")
|
34
|
+
super("#{base}\n\nExample:\n #{example}")
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
@@ -49,7 +52,7 @@ module Micro
|
|
49
52
|
end
|
50
53
|
|
51
54
|
def self.by_wrong_usage?(exception)
|
52
|
-
exception.is_a?(
|
55
|
+
exception.is_a?(InvalidResult) || exception.is_a?(UnexpectedResult) || exception.is_a?(ArgumentError)
|
53
56
|
end
|
54
57
|
end
|
55
58
|
end
|
data/lib/micro/case/result.rb
CHANGED
@@ -99,14 +99,11 @@ module Micro
|
|
99
99
|
@__transitions__.clone
|
100
100
|
end
|
101
101
|
|
102
|
-
FetchData = -> (data
|
102
|
+
FetchData = -> (data) do
|
103
103
|
return data if data.is_a?(Hash)
|
104
104
|
return { data => true } if data.is_a?(Symbol)
|
105
|
-
return { exception: data } if data.is_a?(Exception)
|
106
105
|
|
107
|
-
|
108
|
-
|
109
|
-
raise Micro::Case::Error.const_get(err), data
|
106
|
+
{ exception: data } if data.is_a?(Exception)
|
110
107
|
end
|
111
108
|
|
112
109
|
def __set__(is_success, data, type, use_case)
|
@@ -115,7 +112,9 @@ module Micro
|
|
115
112
|
|
116
113
|
@success, @type, @use_case = is_success, type, use_case
|
117
114
|
|
118
|
-
@data = FetchData.call(data
|
115
|
+
@data = FetchData.call(data)
|
116
|
+
|
117
|
+
raise Micro::Case::Error::InvalidResult.new(is_success, type, use_case) unless @data
|
119
118
|
|
120
119
|
__set_transition__ unless @@transition_tracking_disabled
|
121
120
|
|
data/lib/micro/case/version.rb
CHANGED
data/u-case.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
|
26
26
|
spec.required_ruby_version = '>= 2.2.0'
|
27
27
|
|
28
|
-
spec.add_runtime_dependency 'kind', '
|
28
|
+
spec.add_runtime_dependency 'kind', '>= 3.0', '< 5.0'
|
29
29
|
spec.add_runtime_dependency 'u-attributes', '~> 1.1'
|
30
30
|
|
31
31
|
spec.add_development_dependency 'bundler'
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
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.rc2
|
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-07-
|
11
|
+
date: 2020-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kind
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '3.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: u-attributes
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -97,7 +103,6 @@ files:
|
|
97
103
|
- lib/micro/cases/safe/flow.rb
|
98
104
|
- lib/u-case.rb
|
99
105
|
- lib/u-case/with_activemodel_validation.rb
|
100
|
-
- lib/u-case/with_validation.rb
|
101
106
|
- test.sh
|
102
107
|
- u-case.gemspec
|
103
108
|
homepage: https://github.com/serradura/u-case
|