u-case 5.0.0 → 5.1.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: d654bd6a59c3920ef02a3fa0c2b82fb32ff5f695cfe1f4d4565a84c53bf1d86c
4
- data.tar.gz: e42a81c72ad2f49d01f2464e220e72bd201ca0adce6be06f14defa4ee84f67fe
3
+ metadata.gz: a1270d6bb85374361d86582de966908d7e876a108ebb91bad69bd27f451c6885
4
+ data.tar.gz: b947c931285820d04082e97a41936d65a8f3c4a50da49d54afc304b23dae67ba
5
5
  SHA512:
6
- metadata.gz: '090c4536a5205ed89e0cf2e76b163ca127455f90df793980bd33cdc28efecabd35736e543dc2f003954b8131367672dea79319382412dd7ce6ae25121847eab6'
7
- data.tar.gz: 0a9f2345b82957003238137fcd5a4ca081205f3b83c1f8f092d92f153ef3b57dd7d726abef600cdd1b76b7e6983b222931d8903edf984573cf8dd4696851a7cd
6
+ metadata.gz: bc81c0fb34d2f300768b010aeb0357e8007ced4aac12a4443878179c4f68d333cb8d0c0ccbcac04e9f1101d318569c913880f5f11fb2e3ff48f9b9362d73aebf
7
+ data.tar.gz: 9fa4f08d80d2f89f0622ef76553d148a6ea5a2aebdf29019db4e92932ad986d17a6098533c30e5089cd8b3dc6b703118a9a08e507a15b8a24e67cc06c699e524
data/README.md CHANGED
@@ -27,7 +27,7 @@ The main project goals are:
27
27
  Version | Documentation
28
28
  --------- | -------------
29
29
  unreleased| https://github.com/serradura/u-case/blob/main/README.md
30
- 5.0.0 | https://github.com/serradura/u-case/blob/v5.x/README.md
30
+ 5.1.0 | https://github.com/serradura/u-case/blob/v5.x/README.md
31
31
  4.5.1 | https://github.com/serradura/u-case/blob/v4.x/README.md
32
32
 
33
33
  > **Note:** Você entende português? 🇧🇷 🇵🇹 Verifique o [README traduzido em pt-BR](https://github.com/serradura/u-case/blob/main/README.pt-BR.md).
@@ -88,7 +88,7 @@ unreleased| https://github.com/serradura/u-case/blob/main/README.md
88
88
  | u-case | branch | ruby | activemodel | u-attributes |
89
89
  | ---------------- | ------ | -------- | -------------- | -------------- |
90
90
  | unreleased | main | >= 2.7 | >= 6.0 | >= 2.7, < 4.0 |
91
- | 5.0.0 | v5.x | >= 2.7 | >= 6.0 | >= 2.7, < 4.0 |
91
+ | 5.1.0 | v5.x | >= 2.7 | >= 6.0 | >= 2.7, < 4.0 |
92
92
  | 4.5.1 | v4.x | >= 2.2.0 | >= 3.2, <= 8.1 | >= 2.7, < 3.0 |
93
93
 
94
94
  This library is tested (CI matrix) against:
@@ -189,6 +189,8 @@ A `Micro::Case::Result` stores the use cases output data. These are their main m
189
189
  - `#type` a Symbol which gives meaning for the result, this is useful to declare different types of failures or success.
190
190
  - `#data` the result data itself.
191
191
  - `#[]` and `#values_at` are shortcuts to access the `#data` values.
192
+ - `#fetch` and `#fetch_values` are another way of accessing values of the result data, but raises a `KeyError` if the one of the keys are not present in the result.
193
+ - `#keys` returns an array of keys present in the result data.
192
194
  - `#key?` returns `true` if the key is present in `#data`.
193
195
  - `#value?` returns `true` if the given value is present in `#data`.
194
196
  - `#slice` returns a new hash that includes only the given keys. If the given keys don't exist, an empty hash is returned.
data/README.pt-BR.md CHANGED
@@ -27,7 +27,7 @@ Principais objetivos deste projeto:
27
27
  Versão | Documentação
28
28
  --------- | -------------
29
29
  unreleased| https://github.com/serradura/u-case/blob/main/README.md
30
- 5.0.0 | https://github.com/serradura/u-case/blob/v5.x/README.md
30
+ 5.1.0 | https://github.com/serradura/u-case/blob/v5.x/README.md
31
31
  4.5.1 | https://github.com/serradura/u-case/blob/v4.x/README.md
32
32
 
33
33
  ## Índice <!-- omit in toc -->
@@ -86,7 +86,7 @@ unreleased| https://github.com/serradura/u-case/blob/main/README.md
86
86
  | u-case | branch | ruby | activemodel | u-attributes |
87
87
  | ---------------- | ------ | -------- | -------------- | -------------- |
88
88
  | unreleased | main | >= 2.7 | >= 6.0 | >= 2.7, < 4.0 |
89
- | 5.0.0 | v5.x | >= 2.7 | >= 6.0 | >= 2.7, < 4.0 |
89
+ | 5.1.0 | v5.x | >= 2.7 | >= 6.0 | >= 2.7, < 4.0 |
90
90
  | 4.5.1 | v4.x | >= 2.2.0 | >= 3.2, <= 8.1 | >= 2.7, < 3.0 |
91
91
 
92
92
  Esta biblioteca é testada (matriz de CI) contra:
@@ -187,8 +187,10 @@ Um `Micro::Case::Result` armazena os dados de output de um caso de uso. Esses s
187
187
  - `#type` retorna um Symbol que dá significado ao resultado, isso é útil para declarar diferentes tipos de falha e sucesso.
188
188
  - `#data` os dados do resultado (um `Hash`).
189
189
  - `#[]` e `#values_at` são atalhos para acessar as propriedades do `#data`.
190
- - `#key?` retorna `true` se a chave estiver present no `#data`.
191
- - `#value?` retorna `true` se o valor estiver present no `#data`.
190
+ - `#fetch` e `#fetch_values` são outras maneiras de acessar os valores contidos em `#data`, porém se alguma chave não existir, é levantado um `KeyError`.
191
+ - `#keys` retorna uma array com as chaves presentes no resultado.
192
+ - `#key?` retorna `true` se a chave estiver presente no `#data`.
193
+ - `#value?` retorna `true` se o valor estiver presente no `#data`.
192
194
  - `#slice` retorna um novo `Hash` que inclui apenas as chaves fornecidas. Se as chaves fornecidas não existirem, um `Hash` vazio será retornado.
193
195
  - `#on_success` or `#on_failure` são métodos de hooks que te auxiliam a definir o fluxo da aplicação.
194
196
  - `#then` este método permite aplicar novos casos de uso ao resultado atual se ele for sucesso. A ideia dessa feature é a criação de fluxos dinâmicos.
@@ -62,6 +62,18 @@ module Micro
62
62
  data.key?(key)
63
63
  end
64
64
 
65
+ def keys
66
+ data.keys
67
+ end
68
+
69
+ def fetch(*args, &block)
70
+ data.fetch(*args, &block)
71
+ end
72
+
73
+ def fetch_values(*keys, &block)
74
+ Utils::Hashes.fetch_values(data, keys, &block)
75
+ end
76
+
65
77
  def value?(value)
66
78
  data.value?(value)
67
79
  end
@@ -27,6 +27,14 @@ module Micro::Case::Utils
27
27
 
28
28
  hash.select { |key, _value| keys.include?(key) }
29
29
  end
30
+
31
+ def self.fetch_values(hash, keys, &block)
32
+ return hash.fetch_values(*keys, &block) if hash_respond_to?(hash, :fetch_values)
33
+
34
+ keys.each_with_object([]) do |key, values|
35
+ values << hash.fetch(key, &block)
36
+ end
37
+ end
30
38
  end
31
39
 
32
40
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Micro
4
4
  class Case
5
- VERSION = '5.0.0'.freeze
5
+ VERSION = '5.1.0'.freeze
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: u-case
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Serradura