remap 2.2.47 → 2.2.48
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/remap/base.rb +12 -12
- data/lib/remap/rule/map.rb +2 -2
- data/lib/remap/state/extension.rb +15 -22
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a564dcf130adbf8c40eb089d14f498f993362b74823728ec8ad44b98014034e6
|
4
|
+
data.tar.gz: 3dcac97cd1e4c630ec55ccdbdb6c43922f2ce5367d770e471ebaa77f5ae3fc8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 237c0305757a4a12e5d3c24358fd9ed6295d0159baf0bb5786a9b019e3b50c98bd163334b35b04bab99ef1f19adeb232aec234a2aed76ad16ade778c3950606e
|
7
|
+
data.tar.gz: 1c6637383207baf0bd32fd6398f34dc935a5237e2fa67eafa2fccaa1db0d1f9d3f569c6f0695f9c148e737b1c4de15a974a09ba193d0af55ffaf3bef21bad07d
|
data/lib/remap/base.rb
CHANGED
@@ -34,33 +34,33 @@ module Remap
|
|
34
34
|
# Mapper.call({}) # => { api_key: "ABC-123" }
|
35
35
|
#
|
36
36
|
# @example Maps ["A", "B", "C"] to ["A", "C"]
|
37
|
-
# class
|
37
|
+
# class IfNotMapper < Remap::Base
|
38
38
|
# define do
|
39
39
|
# each do
|
40
|
-
# map?.if_not do
|
40
|
+
# map?.if_not do |value|
|
41
41
|
# value.include?("B")
|
42
42
|
# end
|
43
43
|
# end
|
44
44
|
# end
|
45
45
|
# end
|
46
46
|
#
|
47
|
-
#
|
47
|
+
# IfNotMapper.call(["A", "B", "C"]) # => ["A", "C"]
|
48
48
|
#
|
49
49
|
# @example Maps ["A", "B", "C"] to ["B"]
|
50
|
-
# class
|
50
|
+
# class IfMapper < Remap::Base
|
51
51
|
# define do
|
52
52
|
# each do
|
53
|
-
# map?.if do
|
53
|
+
# map?.if do |value|
|
54
54
|
# value.include?("B")
|
55
55
|
# end
|
56
56
|
# end
|
57
57
|
# end
|
58
58
|
# end
|
59
59
|
#
|
60
|
-
#
|
60
|
+
# IfMapper.call(["A", "B", "C"]) # => ["B"]
|
61
61
|
#
|
62
62
|
# @example Maps { a: { b: "A" } } to "A"
|
63
|
-
# class
|
63
|
+
# class EnumMapper < Remap::Base
|
64
64
|
# define do
|
65
65
|
# map(:a, :b).enum do
|
66
66
|
# value "A", "B"
|
@@ -68,11 +68,11 @@ module Remap
|
|
68
68
|
# end
|
69
69
|
# end
|
70
70
|
#
|
71
|
-
#
|
72
|
-
#
|
71
|
+
# EnumMapper.call({ a: { b: "A" } }) # => "A"
|
72
|
+
# EnumMapper.call({ a: { b: "B" } }) # => "B"
|
73
73
|
#
|
74
74
|
# @example Map { people: [{ name: "John" }] } to { names: ["John"] }
|
75
|
-
# class
|
75
|
+
# class PeopleMapper < Remap::Base
|
76
76
|
# define do
|
77
77
|
# map :people, to: :names do
|
78
78
|
# each do
|
@@ -82,12 +82,12 @@ module Remap
|
|
82
82
|
# end
|
83
83
|
# end
|
84
84
|
#
|
85
|
-
#
|
85
|
+
# PeopleMapper.call({ people: [{ name: "John" }] }) # => { names: ["John"] }
|
86
86
|
#
|
87
87
|
# @example Map "Hello" to "Hello!"
|
88
88
|
# class HelloMapper < Remap::Base
|
89
89
|
# define do
|
90
|
-
# map.adjust do
|
90
|
+
# map.adjust do |value|
|
91
91
|
# "#{value}!"
|
92
92
|
# end
|
93
93
|
# end
|
data/lib/remap/rule/map.rb
CHANGED
@@ -117,7 +117,7 @@ module Remap
|
|
117
117
|
# Keeps map, only if block is true
|
118
118
|
#
|
119
119
|
# @example Keep if value contains "A"
|
120
|
-
# map = Remap::Rule::Map::Optional.call(backtrace: caller).if do
|
120
|
+
# map = Remap::Rule::Map::Optional.call(backtrace: caller).if do |value|
|
121
121
|
# value.include?("A")
|
122
122
|
# end
|
123
123
|
#
|
@@ -145,7 +145,7 @@ module Remap
|
|
145
145
|
#
|
146
146
|
|
147
147
|
# @example Keep unless value contains "A"
|
148
|
-
# map = Remap::Rule::Map::Optional.new(backtrace: caller).if_not do
|
148
|
+
# map = Remap::Rule::Map::Optional.new(backtrace: caller).if_not do |value|
|
149
149
|
# value.include?("A")
|
150
150
|
# end
|
151
151
|
#
|
@@ -292,7 +292,21 @@ module Remap
|
|
292
292
|
bind do |value|
|
293
293
|
result = catch :done do
|
294
294
|
tail_path = catch :ignore do
|
295
|
-
|
295
|
+
names = block.parameters.reduce([]) do |acc, (type, name)|
|
296
|
+
case type
|
297
|
+
in :keyreq
|
298
|
+
acc + [name]
|
299
|
+
else
|
300
|
+
acc
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
r = Proc.new(&block).call(value, **only(*names), **options.only(*names)) do |reason|
|
305
|
+
ignore!(reason)
|
306
|
+
end
|
307
|
+
throw :done, r
|
308
|
+
rescue NameError => e
|
309
|
+
fatal!(e.message)
|
296
310
|
rescue KeyError => e
|
297
311
|
[e.key]
|
298
312
|
rescue IndexError
|
@@ -428,27 +442,6 @@ module Remap
|
|
428
442
|
|
429
443
|
throw id, remove_id
|
430
444
|
end
|
431
|
-
|
432
|
-
private
|
433
|
-
|
434
|
-
# Creates a context containing {options} and {self}
|
435
|
-
#
|
436
|
-
# @param value [Any]
|
437
|
-
#
|
438
|
-
# @yieldparam reason [T]
|
439
|
-
#
|
440
|
-
# @return [Struct]
|
441
|
-
def context(value, context: self)
|
442
|
-
::Struct.new(*except(:id).keys, *options.keys, :state, keyword_init: true) do
|
443
|
-
define_method :method_missing do |name, *|
|
444
|
-
context.fatal!("Method [%s] not defined", name)
|
445
|
-
end
|
446
|
-
|
447
|
-
define_method(:skip!) do |message = "Manual skip!"|
|
448
|
-
context.ignore!(message)
|
449
|
-
end
|
450
|
-
end.new(**to_hash, **options, value: value, state: self)
|
451
|
-
end
|
452
445
|
end
|
453
446
|
end
|
454
447
|
end
|