u-case 4.2.1 → 4.2.2

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: b9b498ae868d7b556a8a0e3a35c314e4704e206c8708b195d585bef6a7766b8b
4
- data.tar.gz: 699ee398f8757ffa406ee1fd86e5d54fa757c7a79d30b73e8af86ba51a65f233
3
+ metadata.gz: 472d6a0f07c2e365dcd4157440888be4a140fabd171c1f8bfdf1f30ffd4c109f
4
+ data.tar.gz: 3b255504d5c6c886bcc9aa167ce5ed57930002b92cb730410ec835a17840a15b
5
5
  SHA512:
6
- metadata.gz: b869538c2bff9f728f3dccee9f1be07bd68d47746dae078394e393962a4b29fe881d1909bd574d19ca0ebf82eddb1951932e29cf92aeed00975a73a61b53cb3b
7
- data.tar.gz: 7adc5bf983cdbb9e1ce4cb0eea5ab985ab0df4889ccc43545585381695d5163ec4ca139b7399e41399e736a4989923b3992aece149a6126e6315f9db760a19d0
6
+ metadata.gz: 99c0bd68b866a0a999f86dcd54a13587c05319c068635821e7fc0470f80b92608186d2bb7d263549e11f73951cff06e8f15c5f7586600b660abfb356ab3c5eaf
7
+ data.tar.gz: 2d22c278fc9f1f6e2f845d1477295314efa6b5fd627019d4e4f086ed1542d89d2c14c9df5b466babc4b1d0036c7aba8f0ea6a22163e5314dc1a4d7c3a0482465
data/.travis.sh CHANGED
@@ -2,17 +2,19 @@
2
2
 
3
3
  ruby_v=$(ruby -v)
4
4
 
5
- ACTIVERECORD_VERSION='3.2' bundle update
6
- ACTIVERECORD_VERSION='3.2' ENABLE_TRANSITIONS='true' bundle exec rake test
7
- ACTIVERECORD_VERSION='3.2' ENABLE_TRANSITIONS='false' bundle exec rake test
8
-
9
- ACTIVERECORD_VERSION='4.0' bundle update
10
- ACTIVERECORD_VERSION='4.0' ENABLE_TRANSITIONS='true' bundle exec rake test
11
- ACTIVERECORD_VERSION='4.0' ENABLE_TRANSITIONS='false' bundle exec rake test
12
-
13
- ACTIVERECORD_VERSION='4.1' bundle update
14
- ACTIVERECORD_VERSION='4.1' ENABLE_TRANSITIONS='true' bundle exec rake test
15
- ACTIVERECORD_VERSION='4.1' ENABLE_TRANSITIONS='false' bundle exec rake test
5
+ if [[ $ruby_v =~ '2.2.' ]] || [[ $ruby_v =~ '2.3.' ]]; then
6
+ ACTIVERECORD_VERSION='3.2' bundle update
7
+ ACTIVERECORD_VERSION='3.2' ENABLE_TRANSITIONS='true' bundle exec rake test
8
+ ACTIVERECORD_VERSION='3.2' ENABLE_TRANSITIONS='false' bundle exec rake test
9
+
10
+ ACTIVERECORD_VERSION='4.0' bundle update
11
+ ACTIVERECORD_VERSION='4.0' ENABLE_TRANSITIONS='true' bundle exec rake test
12
+ ACTIVERECORD_VERSION='4.0' ENABLE_TRANSITIONS='false' bundle exec rake test
13
+
14
+ ACTIVERECORD_VERSION='4.1' bundle update
15
+ ACTIVERECORD_VERSION='4.1' ENABLE_TRANSITIONS='true' bundle exec rake test
16
+ ACTIVERECORD_VERSION='4.1' ENABLE_TRANSITIONS='false' bundle exec rake test
17
+ fi
16
18
 
17
19
  ACTIVERECORD_VERSION='4.2' bundle update
18
20
  ACTIVERECORD_VERSION='4.2' ENABLE_TRANSITIONS='true' bundle exec rake test
data/README.md CHANGED
@@ -39,7 +39,7 @@ The main project goals are:
39
39
  Version | Documentation
40
40
  --------- | -------------
41
41
  unreleased| https://github.com/serradura/u-case/blob/main/README.md
42
- 4.2.1 | https://github.com/serradura/u-case/blob/v4.x/README.md
42
+ 4.2.2 | https://github.com/serradura/u-case/blob/v4.x/README.md
43
43
  3.1.0 | https://github.com/serradura/u-case/blob/v3.x/README.md
44
44
  2.6.0 | https://github.com/serradura/u-case/blob/v2.x/README.md
45
45
  1.1.0 | https://github.com/serradura/u-case/blob/v1.x/README.md
@@ -102,7 +102,7 @@ unreleased| https://github.com/serradura/u-case/blob/main/README.md
102
102
  | u-case | branch | ruby | activemodel | u-attributes |
103
103
  | -------------- | ------- | -------- | ------------- | ------------ |
104
104
  | unreleased | main | >= 2.2.0 | >= 3.2, < 6.1 | ~> 2.0 |
105
- | 4.2.1 | v4.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 2.0 |
105
+ | 4.2.2 | v4.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 2.0 |
106
106
  | 3.1.0 | v3.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 1.1 |
107
107
  | 2.6.0 | v2.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 1.1 |
108
108
  | 1.1.0 | v1.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 1.1 |
@@ -39,7 +39,7 @@ Principais objetivos deste projeto:
39
39
  Versão | Documentação
40
40
  --------- | -------------
41
41
  unreleased| https://github.com/serradura/u-case/blob/main/README.md
42
- 4.2.1 | https://github.com/serradura/u-case/blob/v4.x/README.md
42
+ 4.2.2 | https://github.com/serradura/u-case/blob/v4.x/README.md
43
43
  3.1.0 | https://github.com/serradura/u-case/blob/v3.x/README.md
44
44
  2.6.0 | https://github.com/serradura/u-case/blob/v2.x/README.md
45
45
  1.1.0 | https://github.com/serradura/u-case/blob/v1.x/README.md
@@ -70,9 +70,8 @@ unreleased| https://github.com/serradura/u-case/blob/main/README.md
70
70
  - [É possível declarar um fluxo que inclui o próprio caso de uso?](#é-possível-declarar-um-fluxo-que-inclui-o-próprio-caso-de-uso)
71
71
  - [`Micro::Case::Strict` - O que é um caso de uso estrito?](#microcasestrict---o-que-é-um-caso-de-uso-estrito)
72
72
  - [`Micro::Case::Safe` - Existe algum recurso para lidar automaticamente com exceções dentro de um caso de uso ou fluxo?](#microcasesafe---existe-algum-recurso-para-lidar-automaticamente-com-exceções-dentro-de-um-caso-de-uso-ou-fluxo)
73
- - [`Micro::Case::Result#on_exception`](#microcaseresulton_exception)
74
73
  - [`Micro::Cases::Safe::Flow`](#microcasessafeflow)
75
- - [`Micro::Case::Result#on_exception`](#microcaseresulton_exception-1)
74
+ - [`Micro::Case::Result#on_exception`](#microcaseresulton_exception)
76
75
  - [`u-case/with_activemodel_validation` - Como validar os atributos do caso de uso?](#u-casewith_activemodel_validation---como-validar-os-atributos-do-caso-de-uso)
77
76
  - [Se eu habilitei a validação automática, é possível desabilitá-la apenas em casos de uso específicos?](#se-eu-habilitei-a-validação-automática-é-possível-desabilitá-la-apenas-em-casos-de-uso-específicos)
78
77
  - [`Kind::Validator`](#kindvalidator)
@@ -100,7 +99,8 @@ unreleased| https://github.com/serradura/u-case/blob/main/README.md
100
99
 
101
100
  | u-case | branch | ruby | activemodel | u-attributes |
102
101
  | -------------- | ------- | -------- | ------------- | ------------ |
103
- | 4.2.1 | main | >= 2.2.0 | >= 3.2, < 6.1 | ~> 2.0 |
102
+ | unreleased | main | >= 2.2.0 | >= 3.2, < 6.1 | ~> 2.0 |
103
+ | 4.2.2 | v4.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 2.0 |
104
104
  | 3.1.0 | v3.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 1.1 |
105
105
  | 2.6.0 | v2.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 1.1 |
106
106
  | 1.1.0 | v1.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 1.1 |
@@ -976,8 +976,6 @@ result.on_failure(:exception) do |result|
976
976
  end
977
977
  ```
978
978
 
979
- #### `Micro::Case::Result#on_exception`
980
-
981
979
  Se você precisar lidar com um erro específico, recomendo o uso de uma instrução case. Exemplo:
982
980
 
983
981
  ```ruby
@@ -24,7 +24,11 @@ module Micro
24
24
 
25
25
  return result unless block_given?
26
26
 
27
- yield Result::Wrapper.new(result)
27
+ result_wrapper = Result::Wrapper.new(result)
28
+
29
+ yield(result_wrapper)
30
+
31
+ result_wrapper.output
28
32
  end
29
33
 
30
34
  INVALID_INVOCATION_OF_THE_THEN_METHOD =
@@ -4,38 +4,43 @@ module Micro
4
4
  class Case
5
5
  class Result
6
6
  class Wrapper
7
- def initialize(result)
8
- @__is_unknown = true
7
+ attr_reader :output
9
8
 
9
+ def initialize(result)
10
10
  @result = result
11
+ @output = ::Kind::Undefined
12
+
13
+ @__is_unknown = true
11
14
  end
12
15
 
13
16
  def failure(type = nil)
14
- return if @result.success?
17
+ return if @result.success? || !undefined_output?
15
18
 
16
- if result_type?(type)
17
- @__is_unknown = false
18
-
19
- yield(@result)
20
- end
19
+ set_output(yield(@result)) if result_type?(type)
21
20
  end
22
21
 
23
22
  def success(type = nil)
24
- return if @result.failure?
23
+ return if @result.failure? || !undefined_output?
25
24
 
26
- if result_type?(type)
27
- @__is_unknown = false
28
-
29
- yield(@result)
30
- end
25
+ set_output(yield(@result)) if result_type?(type)
31
26
  end
32
27
 
33
28
  def unknown
34
- return yield(@result) if @__is_unknown
29
+ @output = yield(@result) if @__is_unknown && undefined_output?
35
30
  end
36
31
 
37
32
  private
38
33
 
34
+ def set_output(value)
35
+ @__is_unknown = false
36
+
37
+ @output = value
38
+ end
39
+
40
+ def undefined_output?
41
+ ::Kind::Undefined == @output
42
+ end
43
+
39
44
  def result_type?(type)
40
45
  type.nil? || @result.type == type
41
46
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Micro
4
4
  class Case
5
- VERSION = '4.2.1'.freeze
5
+ VERSION = '4.2.2'.freeze
6
6
  end
7
7
  end
@@ -39,7 +39,11 @@ module Micro
39
39
 
40
40
  return result unless block_given?
41
41
 
42
- yield ::Micro::Case::Result::Wrapper.new(result)
42
+ result_wrapper = ::Micro::Case::Result::Wrapper.new(result)
43
+
44
+ yield(result_wrapper)
45
+
46
+ result_wrapper.output
43
47
  end
44
48
 
45
49
  alias __call__ call
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: 4.2.1
4
+ version: 4.2.2
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-10-22 00:00:00.000000000 Z
11
+ date: 2020-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kind