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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1785653f481f4622720634abe0448ef3d41dd522473ca88e8dc75d987ddd4413
4
- data.tar.gz: f497efd7bc60619a86a3b8bb22e15551a4b513fbe4088e92a1718bd6568ec6df
3
+ metadata.gz: dfc46204c461937d19681ae26dca7846a8d36720b735d759023b4c1369ef2a9a
4
+ data.tar.gz: 21bfd7bc9d2c2a13c901672eac77f15da4b7975aeeea925b3f94ff7e36dd1161
5
5
  SHA512:
6
- metadata.gz: d9d77becd6c184bd58765df5d9dbbad8cee87054e6380b259e3463117401d1107cce3549a3a9626cc97f1307766b4aaef40cc32b5a7744a288790fcae6f1ee97
7
- data.tar.gz: b65306eb69ee9a8fe7dc39d943517aca4617181ddb2c473b6ac241edf4674634b1c7517e0f3c41ad14d243c13f7c83a782e9f6971b1212fd1c87cdb0ef14bf2d
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 | Documentation
24
- ---------- | -------------
25
- Unreleased | 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
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, expose `Kind.of.Micro::Case::Result` type checker and 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.
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
- return Success result: { sum: a + b } if Kind.of.Numeric?(a, b)
512
-
513
- Failure(:attributes_arent_numbers)
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
 
@@ -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 InvalidResultData < TypeError
21
- end
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
- class InvalidSuccessResult < InvalidResultData
24
- def initialize(object)
25
- super("Success(result: #{object.inspect}) must be a Hash or Symbol")
26
- end
27
- end
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
- class InvalidFailureResult < InvalidResultData
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?(InvalidResultData) || exception.is_a?(Error::UnexpectedResult) || exception.is_a?(ArgumentError)
55
+ exception.is_a?(InvalidResult) || exception.is_a?(UnexpectedResult) || exception.is_a?(ArgumentError)
53
56
  end
54
57
  end
55
58
  end
@@ -99,14 +99,11 @@ module Micro
99
99
  @__transitions__.clone
100
100
  end
101
101
 
102
- FetchData = -> (data, is_success) do
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
- err = is_success ? :InvalidSuccessResult : :InvalidFailureResult
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, is_success)
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
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Micro
4
4
  class Case
5
- VERSION = '3.0.0.rc1'.freeze
5
+ VERSION = '3.0.0.rc2'.freeze
6
6
  end
7
7
  end
@@ -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', '~> 3.0'
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.rc1
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-21 00:00:00.000000000 Z
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
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- warn 'Deprecation: "u-case/with_validation" will be deprecated in the next major release.' \
4
- 'Please use "u-case/with_activemodel_validation" instead of it.'
5
-
6
- require 'u-case/with_activemodel_validation'