u-case 4.2.2 → 4.3.0

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: 472d6a0f07c2e365dcd4157440888be4a140fabd171c1f8bfdf1f30ffd4c109f
4
- data.tar.gz: 3b255504d5c6c886bcc9aa167ce5ed57930002b92cb730410ec835a17840a15b
3
+ metadata.gz: a59c64287aa0ee26cc6b111f3d228dac413b5ea604216d20a5c039eece22f5c5
4
+ data.tar.gz: 70394e606e6c73a9c59c42dc3669434a2622e5d714923344576c339084ec31cb
5
5
  SHA512:
6
- metadata.gz: 99c0bd68b866a0a999f86dcd54a13587c05319c068635821e7fc0470f80b92608186d2bb7d263549e11f73951cff06e8f15c5f7586600b660abfb356ab3c5eaf
7
- data.tar.gz: 2d22c278fc9f1f6e2f845d1477295314efa6b5fd627019d4e4f086ed1542d89d2c14c9df5b466babc4b1d0036c7aba8f0ea6a22163e5314dc1a4d7c3a0482465
6
+ metadata.gz: e8f15b3614af9ed23016b94010e341da7587beb90efd59eb5ae0c3528ebfa668a75f39c4b12e0dadd843e180a6e361719a8b99d547e356f5fa30f40c31994a68
7
+ data.tar.gz: 1528399ea74cd553526137f9a39f0a9dc18ab092fb0535dea33659e141ff6baf4ab1806b5963b1fe637e50d3f8157527a933444f2422ba5fc9f79b65f1f091cb
data/.travis.sh CHANGED
@@ -1,45 +1,46 @@
1
1
  #!/bin/bash
2
2
 
3
- ruby_v=$(ruby -v)
4
-
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
3
+ RUBY_V=$(ruby -v)
4
+
5
+ function run_with_bundler {
6
+ rm Gemfile.lock
7
+
8
+ if [ ! -z "$1" ]; then
9
+ bundle_cmd="bundle _$1_"
10
+ else
11
+ bundle_cmd="bundle"
12
+ fi
13
+
14
+ eval "$2 $bundle_cmd update"
15
+ eval "$2 ENABLE_TRANSITIONS=true $bundle_cmd exec rake test"
16
+ eval "$2 ENABLE_TRANSITIONS=false $bundle_cmd exec rake test"
17
+ }
18
+
19
+ function run_with_ar_version_and_bundler {
20
+ run_with_bundler "$2" "ACTIVERECORD_VERSION=$1"
21
+ }
22
+
23
+ RUBY_2_2345="ruby 2.[2345]."
24
+
25
+ if [[ $RUBY_V =~ $RUBY_2_2345 ]]; then
26
+ run_with_bundler "$BUNDLER_V1"
27
+
28
+ run_with_ar_version_and_bundler "3.2" "$BUNDLER_V1"
29
+ run_with_ar_version_and_bundler "4.0" "$BUNDLER_V1"
30
+ run_with_ar_version_and_bundler "4.1" "$BUNDLER_V1"
31
+ run_with_ar_version_and_bundler "4.2" "$BUNDLER_V1"
32
+ run_with_ar_version_and_bundler "5.0" "$BUNDLER_V1"
33
+ run_with_ar_version_and_bundler "5.1" "$BUNDLER_V1"
34
+ run_with_ar_version_and_bundler "5.2" "$BUNDLER_V1"
17
35
  fi
18
36
 
19
- ACTIVERECORD_VERSION='4.2' bundle update
20
- ACTIVERECORD_VERSION='4.2' ENABLE_TRANSITIONS='true' bundle exec rake test
21
- ACTIVERECORD_VERSION='4.2' ENABLE_TRANSITIONS='false' bundle exec rake test
22
-
23
- ACTIVERECORD_VERSION='5.0' bundle update
24
- ACTIVERECORD_VERSION='5.0' ENABLE_TRANSITIONS='true' bundle exec rake test
25
- ACTIVERECORD_VERSION='5.0' ENABLE_TRANSITIONS='false' bundle exec rake test
37
+ RUBY_2_567="ruby 2.[567]."
38
+ RUBY_3_x_x="ruby 3.0."
26
39
 
27
- ACTIVERECORD_VERSION='5.1' bundle update
28
- ACTIVERECORD_VERSION='5.1' ENABLE_TRANSITIONS='true' bundle exec rake test
29
- ACTIVERECORD_VERSION='5.1' ENABLE_TRANSITIONS='false' bundle exec rake test
40
+ if [[ $RUBY_V =~ $RUBY_2_567 ]] || [[ $RUBY_V =~ $RUBY_3_x_x ]]; then
41
+ gem install bundler -v ">= 2" --no-doc
30
42
 
31
- if [[ ! $ruby_v =~ '2.2.0' ]]; then
32
- ACTIVERECORD_VERSION='5.2' bundle update
33
- ACTIVERECORD_VERSION='5.2' ENABLE_TRANSITIONS='true' bundle exec rake test
34
- ACTIVERECORD_VERSION='5.2' ENABLE_TRANSITIONS='false' bundle exec rake test
43
+ run_with_bundler
44
+ run_with_ar_version_and_bundler "6.0"
45
+ run_with_ar_version_and_bundler "6.1"
35
46
  fi
36
-
37
- if [[ $ruby_v =~ '2.5.' ]] || [[ $ruby_v =~ '2.6.' ]] || [[ $ruby_v =~ '2.7.' ]]; then
38
- ACTIVERECORD_VERSION='6.0' bundle update
39
- ACTIVERECORD_VERSION='6.0' ENABLE_TRANSITIONS='true' bundle exec rake test
40
- ACTIVERECORD_VERSION='6.0' ENABLE_TRANSITIONS='false' bundle exec rake test
41
- fi
42
-
43
- bundle update
44
- ENABLE_TRANSITIONS='true' bundle exec rake test
45
- ENABLE_TRANSITIONS='false' bundle exec rake test
data/.travis.yml CHANGED
@@ -1,21 +1,24 @@
1
-
2
1
  language: ruby
3
2
 
4
- sudo: false
3
+ cache:
4
+ bundler: true
5
+ directories:
6
+ - /home/travis/.rvm/
5
7
 
6
8
  rvm:
7
- - 2.2.0
9
+ - 2.2.2
8
10
  - 2.3.0
9
11
  - 2.4.0
10
12
  - 2.5.0
11
13
  - 2.6.0
12
14
  - 2.7.0
15
+ - 3.0.0
13
16
 
14
- cache: bundler
17
+ env:
18
+ - BUNDLER_V1="1.17.3"
15
19
 
16
20
  before_install:
17
- - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
18
- - gem install bundler -v '< 2'
21
+ - gem install bundler -v "$BUNDLER_V1"
19
22
 
20
23
  install: bundle install --jobs=3 --retry=3
21
24
 
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source "https://rubygems.org"
2
2
 
3
3
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
- activerecord_version = ENV.fetch('ACTIVERECORD_VERSION', '6.1')
5
+ activerecord_version = ENV.fetch('ACTIVERECORD_VERSION', '7')
6
6
 
7
7
  activerecord = case activerecord_version
8
8
  when '3.2' then '3.2.22'
@@ -11,8 +11,9 @@ activerecord = case activerecord_version
11
11
  when '4.2' then '4.2.11'
12
12
  when '5.0' then '5.0.7'
13
13
  when '5.1' then '5.1.7'
14
- when '5.2' then '5.2.3'
15
- when '6.0' then '6.0.3'
14
+ when '5.2' then '5.2.4'
15
+ when '6.0' then '6.0.3.4'
16
+ when '6.1' then '6.1.2'
16
17
  end
17
18
 
18
19
  simplecov_version =
@@ -30,7 +31,7 @@ group :test do
30
31
  if activerecord
31
32
  sqlite3 =
32
33
  case activerecord
33
- when /\A6\.0/, nil then '~> 1.4.0'
34
+ when /\A6\.(0|1)/, nil then '~> 1.4.0'
34
35
  else '~> 1.3.0'
35
36
  end
36
37
 
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.2 | https://github.com/serradura/u-case/blob/v4.x/README.md
42
+ 4.3.0 | 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
@@ -99,13 +99,13 @@ unreleased| https://github.com/serradura/u-case/blob/main/README.md
99
99
 
100
100
  ## Compatibility
101
101
 
102
- | u-case | branch | ruby | activemodel | u-attributes |
103
- | -------------- | ------- | -------- | ------------- | ------------ |
104
- | unreleased | main | >= 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
- | 3.1.0 | v3.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 1.1 |
107
- | 2.6.0 | v2.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 1.1 |
108
- | 1.1.0 | v1.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 1.1 |
102
+ | u-case | branch | ruby | activemodel | u-attributes |
103
+ | -------------- | ------- | -------- | ------------- | ------------- |
104
+ | unreleased | main | >= 2.2.0 | >= 3.2, < 7.0 | >= 2.7, < 3.0 |
105
+ | 4.3.0 | v4.x | >= 2.2.0 | >= 3.2, < 7.0 | >= 2.7, < 3.0 |
106
+ | 3.1.0 | v3.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 1.1 |
107
+ | 2.6.0 | v2.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 1.1 |
108
+ | 1.1.0 | v1.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 1.1 |
109
109
 
110
110
  > Note: The activemodel is an optional dependency, this module [can be enabled](#u-casewith_activemodel_validation---how-to-validate-use-case-attributes) to validate the use cases' attributes.
111
111
 
@@ -115,7 +115,7 @@ unreleased| https://github.com/serradura/u-case/blob/main/README.md
115
115
 
116
116
  A simple type system (at runtime) for Ruby.
117
117
 
118
- It is used to validate some internal u-case's methods input. This gem also exposes an [`ActiveModel validator`](https://github.com/serradura/kind#kindvalidator-activemodelvalidations) when requiring the [`u-case/with_activemodel_validation`](#u-casewith_activemodel_validation---how-to-validate-use-case-attributes) module, or when the [`Micro::Case.config`](#microcaseconfig) was used to enable it. Lastly, two type checkers are available through it: [`Kind::Of::Micro::Case`, `Kind::Of::Micro::Case::Result`](https://github.com/serradura/kind#registering-new-custom-type-checker).
118
+ It is used to validate some internal u-case's methods input. This gem also exposes an [`ActiveModel validator`](https://github.com/serradura/kind#kindvalidator-activemodelvalidations) when requiring the [`u-case/with_activemodel_validation`](#u-casewith_activemodel_validation---how-to-validate-use-case-attributes) module, or when the [`Micro::Case.config`](#microcaseconfig) was used to enable it.
119
119
  2. [`u-attributes`](https://github.com/serradura/u-attributes) gem.
120
120
 
121
121
  This gem allows defining read-only attributes, that is, your objects will have only getters to access their attributes data.
@@ -1052,8 +1052,8 @@ Divide
1052
1052
  # Can't divide a number by 0
1053
1053
  # Oh no, something went wrong!
1054
1054
 
1055
- Divide.
1056
- .call(a: 2, b: '2').
1055
+ Divide
1056
+ .call(a: 2, b: '2')
1057
1057
  .on_success { |result| puts result[:division] }
1058
1058
  .on_exception(TypeError) { puts 'Please, use only numeric attributes.' }
1059
1059
  .on_exception(ZeroDivisionError) { |_error| puts "Can't divide a number by 0." }
data/README.pt-BR.md CHANGED
@@ -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.2 | https://github.com/serradura/u-case/blob/v4.x/README.md
42
+ 4.3.0 | 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
@@ -97,13 +97,13 @@ unreleased| https://github.com/serradura/u-case/blob/main/README.md
97
97
 
98
98
  ## Compatibilidade
99
99
 
100
- | u-case | branch | ruby | activemodel | u-attributes |
101
- | -------------- | ------- | -------- | ------------- | ------------ |
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
- | 3.1.0 | v3.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 1.1 |
105
- | 2.6.0 | v2.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 1.1 |
106
- | 1.1.0 | v1.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 1.1 |
100
+ | u-case | branch | ruby | activemodel | u-attributes- |
101
+ | -------------- | ------- | -------- | ------------- | ------------- |
102
+ | unreleased | main | >= 2.2.0 | >= 3.2, < 7.0 | >= 2.7, < 3.0 |
103
+ | 4.3.0 | v4.x | >= 2.2.0 | >= 3.2, < 7.0 | >= 2.7, < 3.0 |
104
+ | 3.1.0 | v3.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 1.1 |
105
+ | 2.6.0 | v2.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 1.1 |
106
+ | 1.1.0 | v1.x | >= 2.2.0 | >= 3.2, < 6.1 | ~> 1.1 |
107
107
 
108
108
  > Nota: O activemodel é uma dependência opcional, esse módulo que [pode ser habilitado](#u-casewith_activemodel_validation---como-validar-os-atributos-do-caso-de-uso) para validar os atributos dos casos de uso.
109
109
 
@@ -113,7 +113,7 @@ unreleased| https://github.com/serradura/u-case/blob/main/README.md
113
113
 
114
114
  Sistema de tipos simples (em runtime) para Ruby.
115
115
 
116
- É usado para validar os inputs de alguns métodos do u-case, além de expor um validador de tipos através do [`activemodel validation`](https://github.com/serradura/kind#kindvalidator-activemodelvalidations) ([veja como habilitar]((#u-casewith_activemodel_validation---how-to-validate-use-case-attributes))). Por fim, ele também expõe dois verificadores de tipo: [`Kind::Of::Micro::Case`, `Kind::Of::Micro::Case::Result`](https://github.com/serradura/kind#registering-new-custom-type-checker).
116
+ É usado para validar os inputs de alguns métodos do u-case, além de expor um validador de tipos através do [`activemodel validation`](https://github.com/serradura/kind#kindvalidator-activemodelvalidations) ([veja como habilitar]((#u-casewith_activemodel_validation---how-to-validate-use-case-attributes))).
117
117
  2. [`u-attributes`](https://github.com/serradura/u-attributes) gem.
118
118
 
119
119
  Essa gem permite definir atributos de leitura (read-only), ou seja, os seus objetos só terão getters para acessar os dados dos seus atributos.
@@ -1053,8 +1053,8 @@ Divide
1053
1053
  # Can't divide a number by 0
1054
1054
  # Oh no, something went wrong!
1055
1055
 
1056
- Divide.
1057
- .call(a: 2, b: '2').
1056
+ Divide
1057
+ .call(a: 2, b: '2')
1058
1058
  .on_success { |result| puts result[:division] }
1059
1059
  .on_exception(TypeError) { puts 'Please, use only numeric attributes.' }
1060
1060
  .on_exception(ZeroDivisionError) { |_error| puts "Can't divide a number by 0." }
data/lib/micro/case.rb CHANGED
@@ -243,6 +243,21 @@ module Micro
243
243
  __get_result(false, value, type)
244
244
  end
245
245
 
246
+
247
+ def Check(type = nil, result: nil, on: Kind::Empty::HASH)
248
+ result_key = type || :check
249
+
250
+ if value
251
+ result = on[:success] || { result_key => true }
252
+
253
+ Success(type || :ok, result: result)
254
+ else
255
+ result = on[:failure] || { result_key => false }
256
+
257
+ Failure(type || :error, result: result)
258
+ end
259
+ end
260
+
246
261
  def __get_result(is_success, value, type)
247
262
  @__result.__set__(is_success, value, type, self)
248
263
  end
@@ -9,12 +9,12 @@ module Micro
9
9
 
10
10
  def enable_transitions=(value)
11
11
  Micro::Case::Result.class_variable_set(
12
- :@@transitions_enabled, Kind::Of::Boolean(value)
12
+ :@@transitions_enabled, Kind::Boolean[value]
13
13
  )
14
14
  end
15
15
 
16
16
  def enable_activemodel_validation=(value)
17
- return unless Kind::Of::Boolean(value)
17
+ return unless Kind::Boolean[value]
18
18
 
19
19
  require 'micro/case/with_activemodel_validation'
20
20
  end
@@ -22,7 +22,7 @@ module Micro
22
22
  def set_activemodel_validation_errors_failure=(value)
23
23
  return unless value
24
24
 
25
- @activemodel_validation_errors_failure = Kind.of(Symbol, value)
25
+ @activemodel_validation_errors_failure = Kind::Symbol[value]
26
26
  end
27
27
 
28
28
  def activemodel_validation_errors_failure
@@ -8,8 +8,6 @@ module Micro
8
8
  require 'micro/case/result/wrapper'
9
9
  require 'micro/case/result/transitions'
10
10
 
11
- Kind::Types.add(self)
12
-
13
11
  INVALID_INVOCATION_OF_THE_THEN_METHOD =
14
12
  Error::InvalidInvocationOfTheThenMethod.new("#{self.name}#")
15
13
 
@@ -138,32 +136,12 @@ module Micro
138
136
  yield_self(&block)
139
137
  else
140
138
  return yield_self if !use_case && can_yield_self
141
- return failure? ? self : __call_proc(use_case, 'then(-> {})'.freeze) if use_case.is_a?(Proc)
142
- return failure? ? self : __call_method(use_case, attributes) if use_case.is_a?(Method)
143
-
144
- raise INVALID_INVOCATION_OF_THE_THEN_METHOD unless ::Micro.case_or_flow?(use_case)
145
-
146
- return self if failure?
147
-
148
- input = attributes.is_a?(Hash) ? self.data.merge(attributes) : self.data
149
-
150
- if use_case.is_a?(::Micro::Cases::Flow)
151
- use_case.call!(input: input, result: self)
152
- else
153
- use_case.__new__(self, input).__call__
154
- end
139
+ return failure? ? self : __call_use_case(use_case, attributes)
155
140
  end
156
141
  end
157
142
 
158
143
  def |(arg)
159
- return self if failure?
160
-
161
- return __call_proc(arg, '| -> {}'.freeze) if arg.is_a?(Proc)
162
- return __call_method(arg) if arg.is_a?(Method)
163
-
164
- raise INVALID_INVOCATION_OF_THE_THEN_METHOD unless ::Micro.case_or_flow?(arg)
165
-
166
- failure? ? self : arg.__new__(self, data).__call__
144
+ failure? ? self : __call_use_case(arg)
167
145
  end
168
146
 
169
147
  def transitions
@@ -221,6 +199,28 @@ module Micro
221
199
  @__accessible_attributes.dup
222
200
  end
223
201
 
202
+ def __call_use_case(use_case, attributes = nil)
203
+ case use_case
204
+ when Proc
205
+ __call_proc(use_case, 'then(-> {})'.freeze)
206
+ when Method
207
+ __call_method(use_case, attributes)
208
+ when String, Symbol
209
+ use_case_method = self.use_case.method(use_case)
210
+ __call_method(use_case_method, attributes)
211
+ else
212
+ raise INVALID_INVOCATION_OF_THE_THEN_METHOD unless ::Micro.case_or_flow?(use_case)
213
+
214
+ input = attributes.is_a?(Hash) ? self.data.merge(attributes) : self.data
215
+
216
+ if use_case.is_a?(::Micro::Cases::Flow)
217
+ use_case.call!(input: input, result: self)
218
+ else
219
+ use_case.__new__(self, input).__call__
220
+ end
221
+ end
222
+ end
223
+
224
224
  def __call_proc(fn, expected)
225
225
  __update_accessible_attributes(@__accumulated_data)
226
226
 
@@ -1,36 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Micro
4
- class Case
5
- module Utils
3
+ module Micro::Case::Utils
6
4
 
7
- module Hashes
8
- def self.respond_to?(hash, method)
9
- Kind.of(Hash, hash).respond_to?(method)
10
- end
11
-
12
- def self.symbolize_keys(hash)
13
- return hash.transform_keys { |key| key.to_sym rescue key } if respond_to?(hash, :transform_keys)
5
+ module Hashes
6
+ def self.respond_to?(hash, method)
7
+ Kind::Hash[hash].respond_to?(method)
8
+ end
14
9
 
15
- hash.each_with_object({}) do |(k, v), memo|
16
- key = k.to_sym rescue k
17
- memo[key] = v
18
- end
19
- end
10
+ def self.symbolize_keys(hash)
11
+ return hash.transform_keys { |key| key.to_sym rescue key } if respond_to?(hash, :transform_keys)
20
12
 
21
- def self.stringify_keys(hash)
22
- return hash.transform_keys(&:to_s) if respond_to?(hash, :transform_keys)
13
+ hash.each_with_object({}) do |(k, v), memo|
14
+ key = k.to_sym rescue k
15
+ memo[key] = v
16
+ end
17
+ end
23
18
 
24
- hash.each_with_object({}) { |(k, v), memo| memo[k.to_s] = v }
25
- end
19
+ def self.stringify_keys(hash)
20
+ return hash.transform_keys(&:to_s) if respond_to?(hash, :transform_keys)
26
21
 
27
- def self.slice(hash, keys)
28
- return hash.slice(*keys) if respond_to?(hash, :slice)
22
+ hash.each_with_object({}) { |(k, v), memo| memo[k.to_s] = v }
23
+ end
29
24
 
30
- hash.select { |key, _value| keys.include?(key) }
31
- end
32
- end
25
+ def self.slice(hash, keys)
26
+ return hash.slice(*keys) if respond_to?(hash, :slice)
33
27
 
28
+ hash.select { |key, _value| keys.include?(key) }
34
29
  end
35
30
  end
31
+
36
32
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Micro
4
4
  class Case
5
- VERSION = '4.2.2'.freeze
5
+ VERSION = '4.3.0'.freeze
6
6
  end
7
7
  end
@@ -5,7 +5,7 @@ module Micro
5
5
  class Map
6
6
  IsAUseCaseOrFlowWithDefaults = -> arg { arg.is_a?(Array) && Micro.case_or_flow?(arg[0]) && arg[1].is_a?(Hash) }
7
7
  IsAUseCaseOrFlow = -> arg { Micro.case_or_flow?(arg) || IsAUseCaseOrFlowWithDefaults[arg] }
8
- HasValidArgs = -> (args) { Kind.of(Array, args).all?(&IsAUseCaseOrFlow) }
8
+ HasValidArgs = -> (args) { Kind::Array[args].all?(&IsAUseCaseOrFlow) }
9
9
 
10
10
  attr_reader :use_cases
11
11
 
@@ -28,7 +28,7 @@ module Micro
28
28
  end
29
29
 
30
30
  def call(arg = {})
31
- hash = Kind.of(Hash, arg)
31
+ hash = Kind::Hash[arg]
32
32
 
33
33
  use_cases.map(&GetUseCaseResult[hash])
34
34
  end
data/u-case.gemspec CHANGED
@@ -25,8 +25,8 @@ 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', '< 5.0'
29
- spec.add_runtime_dependency 'u-attributes', '~> 2.0'
28
+ spec.add_runtime_dependency 'kind', '>= 4.0', '< 6.0'
29
+ spec.add_runtime_dependency 'u-attributes', '>= 2.7', '< 3.0'
30
30
 
31
31
  spec.add_development_dependency 'bundler'
32
32
  spec.add_development_dependency 'rake', '~> 13.0'
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.2
4
+ version: 4.3.0
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-12-04 00:00:00.000000000 Z
11
+ date: 2021-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kind
@@ -16,34 +16,40 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '4.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5.0'
22
+ version: '6.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '3.0'
29
+ version: '4.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5.0'
32
+ version: '6.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: u-attributes
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '2.7'
40
+ - - "<"
38
41
  - !ruby/object:Gem::Version
39
- version: '2.0'
42
+ version: '3.0'
40
43
  type: :runtime
41
44
  prerelease: false
42
45
  version_requirements: !ruby/object:Gem::Requirement
43
46
  requirements:
44
- - - "~>"
47
+ - - ">="
45
48
  - !ruby/object:Gem::Version
46
- version: '2.0'
49
+ version: '2.7'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '3.0'
47
53
  - !ruby/object:Gem::Dependency
48
54
  name: bundler
49
55
  requirement: !ruby/object:Gem::Requirement