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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d745b7e030764a548c8cb8b2651e89cf22485154120bab89053743653d0ccd9a
4
- data.tar.gz: '04408f1457593d3c2f3fb8fc5d52f275b74e9d3f0eb31a4088d073ee93ddeeb6'
3
+ metadata.gz: a564dcf130adbf8c40eb089d14f498f993362b74823728ec8ad44b98014034e6
4
+ data.tar.gz: 3dcac97cd1e4c630ec55ccdbdb6c43922f2ce5367d770e471ebaa77f5ae3fc8c
5
5
  SHA512:
6
- metadata.gz: 2fb3e7f89ed0dea90a33a33dee5f5a5b358f22de24b24a64e531a7a84196da067e621060ab21045efb810c02cc8af0f53e7ca43d36ddad3124fb1a2212973a81
7
- data.tar.gz: ad67a4ec14390748e9df5d77f8093c44143ae63df023a5ea84434ab79f7c5a894f1df0cdf7b3ce38b19fea44668b19ba269b3185d18d6deaa435a4620f1a733f
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 Mapper < Remap::Base
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
- # Mapper.call(["A", "B", "C"]) # => ["A", "C"]
47
+ # IfNotMapper.call(["A", "B", "C"]) # => ["A", "C"]
48
48
  #
49
49
  # @example Maps ["A", "B", "C"] to ["B"]
50
- # class Mapper < Remap::Base
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
- # Mapper.call(["A", "B", "C"]) # => ["B"]
60
+ # IfMapper.call(["A", "B", "C"]) # => ["B"]
61
61
  #
62
62
  # @example Maps { a: { b: "A" } } to "A"
63
- # class Mapper < Remap::Base
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
- # Mapper.call({ a: { b: "A" } }) # => "A"
72
- # Mapper.call({ a: { b: "B" } }) # => "B"
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 Mapper < Remap::Base
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
- # Mapper.call({ people: [{ name: "John" }] }) # => { names: ["John"] }
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
@@ -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
- throw :done, context(value).instance_exec(value, &block)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remap
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.47
4
+ version: 2.2.48
5
5
  platform: ruby
6
6
  authors:
7
7
  - Linus Oleander