remap 2.2.50 → 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: a036948beb3769bca586002c771569e54639a3a60314bac615a8f2dbb25a546b
4
- data.tar.gz: 966315eb1929aa681d95d477e72a4545bdc435a4a4e3583d1cec875e8061d479
3
+ metadata.gz: '0399e47c927d5179a2a969ffa5feb480c7c9f39c32eb4973c2fe2f3ed11226f8'
4
+ data.tar.gz: be2ba0c49c8bf13a1a6d6879a9a7ee34770a7990f2f6e04debff24040be71c14
5
5
  SHA512:
6
- metadata.gz: f9afa516dd3d8248b714744598c847d04525f1d2d0e0f320128c6b785281b0a40e93d1b444cca6b4d1b6199bdb85dffa5fe4cda1c1d9ef97ec58f348a4994271
7
- data.tar.gz: 72c2bfaaecc2553b3097f5b464cb03772314dab2127b5154d64b6e99e7e0c028ccba987c94acda788c7fa9229f48a626c895d558a6a974d8cbf95ae16b2d7ea5
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.50
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-16 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
@@ -150,76 +150,6 @@ dependencies:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: 2.5.1
153
- - !ruby/object:Gem::Dependency
154
- name: rake
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: '0'
167
- - !ruby/object:Gem::Dependency
168
- name: rspec-collection_matchers
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - ">="
172
- - !ruby/object:Gem::Version
173
- version: '0'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - ">="
179
- - !ruby/object:Gem::Version
180
- version: '0'
181
- - !ruby/object:Gem::Dependency
182
- name: rubocop
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - "~>"
186
- - !ruby/object:Gem::Version
187
- version: 1.23.0
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - "~>"
193
- - !ruby/object:Gem::Version
194
- version: 1.23.0
195
- - !ruby/object:Gem::Dependency
196
- name: rubocop-performance
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - ">="
200
- - !ruby/object:Gem::Version
201
- version: '0'
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - ">="
207
- - !ruby/object:Gem::Version
208
- version: '0'
209
- - !ruby/object:Gem::Dependency
210
- name: rubocop-rake
211
- requirement: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - ">="
214
- - !ruby/object:Gem::Version
215
- version: '0'
216
- type: :development
217
- prerelease: false
218
- version_requirements: !ruby/object:Gem::Requirement
219
- requirements:
220
- - - ">="
221
- - !ruby/object:Gem::Version
222
- version: '0'
223
153
  description: |
224
154
  Re:map; an expressive and feature-rich data transformation mapper for Ruby 3.
225
155
  It gives the developer the expressive power of JSONPath, without the hassle of
@@ -309,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
309
239
  - !ruby/object:Gem::Version
310
240
  version: '0'
311
241
  requirements: []
312
- rubygems_version: 3.2.32
242
+ rubygems_version: 3.3.7
313
243
  signing_key:
314
244
  specification_version: 4
315
245
  summary: An expressive and feature-complete data mapper with intuitive syntax thanks