remap 2.2.51 → 2.2.52

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: 9d9b65b616274770efbfd7e0cbc0a1267dad1f362c8b00031b389467099fd7dd
4
- data.tar.gz: ce414f535c4a5d045b7cda3b3e265ddca8ac100ed2937a55d5e812a033e4beea
3
+ metadata.gz: '0399e47c927d5179a2a969ffa5feb480c7c9f39c32eb4973c2fe2f3ed11226f8'
4
+ data.tar.gz: be2ba0c49c8bf13a1a6d6879a9a7ee34770a7990f2f6e04debff24040be71c14
5
5
  SHA512:
6
- metadata.gz: be33c29fca4e449ce50e40d25ed31153ac076c6ab4fdbeb56ec911f5e6b66a2502b496899a655619bbd230e303320e5b279730e4e412f3b3ef7f720fd1a709b1
7
- data.tar.gz: 69bdec20f5147b7a9def5404c3a00c73a8a15f247d201189d96ee9b5c345795b9fc41ea3b65ba2244154ab0ade712b8b0aeee7d10d3ddf87737e402b761c9c88
6
+ metadata.gz: 61cdc42f2748d22bdddc4c7972346ba085bbeb7a6a4846f0bad0d9d076a513aa83623315bc3885987dbf509400d5be7387873a63fc5f1b612446fd04daf8ecd2
7
+ data.tar.gz: 67567c687729a65225d679758b58371ac0480ce77cc19bb8c24c984a36866f3cd2e4b666ee1f73d3ddf9b45286b7a6231dba8ff246037d3e86099777bc2198a2
@@ -5,6 +5,21 @@ module Remap
5
5
  using Extensions::Enumerable
6
6
  using State::Extension
7
7
 
8
+ # TODO: Move & Test
9
+ module Dispatch
10
+ refine Static::Option do
11
+ def call(...)
12
+ super.value
13
+ end
14
+ end
15
+
16
+ refine Object do
17
+ def call(_)
18
+ self
19
+ end
20
+ end
21
+ end
22
+
8
23
  # Sets the value to a given path
9
24
  #
10
25
  # @example Maps "A" to { a: { b: { c: "A" } } }
@@ -13,12 +28,18 @@ module Remap
13
28
  #
14
29
  # result.fetch(:value) # => { a: { b: { c: "A" } } }
15
30
  class Output < Unit
31
+ using Dispatch
32
+
16
33
  attribute :selectors, [Types::Key]
17
34
 
18
35
  # @return [State]
19
36
  def call(state)
37
+ mapped = selectors.map do |selector|
38
+ selector.call(state)
39
+ end
40
+
20
41
  state.fmap do |value|
21
- selectors.hide(value)
42
+ mapped.hide(value)
22
43
  end
23
44
  end
24
45
  end
@@ -109,27 +109,27 @@ module Remap
109
109
  # @return [State]
110
110
  def map(&block)
111
111
  result = case self
112
- in { value: Array => array }
113
- array.each_with_index.each_with_object([]) do |(value, index), array|
114
- s1 = block[set(value, index: index)]
115
-
116
- if s1.key?(:value)
117
- array << s1[:value]
118
- end
119
- end
120
- in { value: Hash => hash }
121
- hash.each_with_object({}) do |(key, value), acc|
122
- s1 = block[set(value, key: key)]
123
-
124
- if s1.key?(:value)
125
- acc[key] = s1[:value]
126
- end
127
- end
128
- in { value: }
129
- fatal!("Expected an enumerable got %s", value.class)
130
- else
131
- return self
132
- end
112
+ in { value: Array => array }
113
+ array.each_with_index.each_with_object([]) do |(value, index), array|
114
+ s1 = block[set(value, index: index)]
115
+
116
+ if s1.key?(:value)
117
+ array << s1[:value]
118
+ end
119
+ end
120
+ in { value: Hash => hash }
121
+ hash.each_with_object({}) do |(key, value), acc|
122
+ s1 = block[set(value, key: key)]
123
+
124
+ if s1.key?(:value)
125
+ acc[key] = s1[:value]
126
+ end
127
+ end
128
+ in { value: }
129
+ fatal!("Expected an enumerable got %s", value.class)
130
+ else
131
+ return self
132
+ end
133
133
 
134
134
  set(result)
135
135
  end
@@ -402,27 +402,23 @@ module Remap
402
402
  # @return [Failure]
403
403
  def failure(reason = Undefined)
404
404
  failures = case [path, reason]
405
- in [_, Undefined]
406
- return Failure.new(failures: notices)
407
- in [_, Notice => notice]
408
- [notice]
409
- in [path, Array => reasons]
410
- reasons.map do |inner_reason|
411
- Notice.call(path: path, reason: inner_reason, **only(:value))
412
- end
413
- in [path, String => reason]
414
- [Notice.call(path: path, reason: reason, **only(:value))]
415
- in [path, Hash => errors]
416
- errors.paths.flat_map do |sufix|
417
- Array.wrap(errors.dig(*sufix)).map do |inner_reason|
418
- Notice.call(
419
- reason: inner_reason,
420
- path: path + sufix,
421
- **only(:value)
422
- )
423
- end
424
- end
425
- end
405
+ in [_, Undefined]
406
+ return Failure.new(failures: notices)
407
+ in [_, Notice => notice]
408
+ [notice]
409
+ in [path, Array => reasons]
410
+ reasons.map do |inner_reason|
411
+ Notice.call(path: path, reason: inner_reason, **only(:value))
412
+ end
413
+ in [path, String => reason]
414
+ [Notice.call(path: path, reason: reason, **only(:value))]
415
+ in [path, Hash => errors]
416
+ errors.paths.flat_map do |sufix|
417
+ Array.wrap(errors.dig(*sufix)).map do |inner_reason|
418
+ Notice.call(reason: inner_reason, path: path + sufix, **only(:value))
419
+ end
420
+ end
421
+ end
426
422
 
427
423
  Failure.new(failures: failures, notices: notices)
428
424
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remap
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.51
4
+ version: 2.2.52
5
5
  platform: ruby
6
6
  authors:
7
7
  - Linus Oleander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-24 00:00:00.000000000 Z
11
+ date: 2022-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -239,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
239
  - !ruby/object:Gem::Version
240
240
  version: '0'
241
241
  requirements: []
242
- rubygems_version: 3.2.32
242
+ rubygems_version: 3.3.7
243
243
  signing_key:
244
244
  specification_version: 4
245
245
  summary: An expressive and feature-complete data mapper with intuitive syntax thanks