remap 2.2.45 → 2.2.46
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 +3 -3
- data/lib/remap/catchable.rb +31 -10
- data/lib/remap/compiler.rb +2 -4
- data/lib/remap/rule/block.rb +10 -16
- data/lib/remap/rule/map/optional.rb +6 -6
- data/lib/remap/rule/map/required.rb +13 -1
- data/lib/remap/rule/map.rb +7 -22
- data/lib/remap/state/extension.rb +4 -7
- 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: 71b1a0f8a9cb714d568939ace38b13d053e4c1ddf9131a6040630ff4a1479e4a
|
4
|
+
data.tar.gz: fe768a12f868c085839145d28a609a707c4aacb10a18c16e2276e51b23de0fb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f5f657a29f997cf1161eda204a2ddd38f1c6dcc991c8467732d367bc31302c7bafd1e05f5a7655cc5ef46dea5498b9caec6fb9d75d2bd1e9aa5c7f34f7a8ec9
|
7
|
+
data.tar.gz: 9263defd99a669a7bcee25381df7a74698cb2ab691b5a2cf22e7cfdb83a8898956b1a17e329e7560e920ad762093822b85c40587dd6bdcf77ab2433188857474
|
data/lib/remap/base.rb
CHANGED
@@ -305,11 +305,11 @@ module Remap
|
|
305
305
|
end
|
306
306
|
end
|
307
307
|
|
308
|
-
s1 = catch_ignored do |
|
309
|
-
return context.call(
|
308
|
+
s1 = catch_ignored(state) do |s0|
|
309
|
+
return context.call(s0).then(&constructor).remove_id
|
310
310
|
end
|
311
311
|
|
312
|
-
|
312
|
+
error[s1.failure]
|
313
313
|
end
|
314
314
|
|
315
315
|
private
|
data/lib/remap/catchable.rb
CHANGED
@@ -1,21 +1,42 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Remap
|
4
|
+
# @api private
|
4
5
|
module Catchable
|
5
|
-
|
6
|
-
|
6
|
+
using State::Extension
|
7
|
+
|
8
|
+
# @param state [State]
|
9
|
+
#
|
10
|
+
# @yieldparam state [State]
|
11
|
+
# @yieldparam id [Symbol, String]
|
12
|
+
# @yieldreturn [State<T>]
|
7
13
|
#
|
8
|
-
# @return [T]
|
9
|
-
def catch_ignored(&block)
|
10
|
-
|
14
|
+
# @return [State<T>]
|
15
|
+
def catch_ignored(state, &block)
|
16
|
+
id = to_id(:ignored)
|
17
|
+
|
18
|
+
catch(id) do
|
19
|
+
block[state.set(id: id), id: id].remove_id
|
20
|
+
end
|
11
21
|
end
|
12
22
|
|
13
|
-
# @
|
14
|
-
# @
|
23
|
+
# @param state [State]
|
24
|
+
# @param backtrace [Array<String>]
|
15
25
|
#
|
16
|
-
# @
|
17
|
-
|
18
|
-
|
26
|
+
# @yieldparam state [State]
|
27
|
+
# @yieldparam id [Symbol, String]
|
28
|
+
# @yieldreturn [State<T>]
|
29
|
+
#
|
30
|
+
# @return [State<T>]
|
31
|
+
# @raise [Failure::Error]
|
32
|
+
def catch_fatal(state, backtrace, &block)
|
33
|
+
id = to_id(:fatal)
|
34
|
+
|
35
|
+
failure = catch(id) do
|
36
|
+
return block[state.set(fatal_id: id), fatal_id: id].remove_fatal_id
|
37
|
+
end
|
38
|
+
|
39
|
+
raise failure.exception(backtrace)
|
19
40
|
end
|
20
41
|
|
21
42
|
private
|
data/lib/remap/compiler.rb
CHANGED
@@ -548,13 +548,13 @@ module Remap
|
|
548
548
|
output: [to].flatten,
|
549
549
|
input: path.flatten
|
550
550
|
},
|
551
|
+
backtrace: backtrace,
|
551
552
|
rule: call(backtrace: backtrace, &block)
|
552
553
|
})
|
553
554
|
end
|
554
555
|
|
555
556
|
def build_embed(s0, mapper, backtrace)
|
556
|
-
|
557
|
-
s1 = s0.set(fatal_id: fatal_id)
|
557
|
+
catch_fatal(s0, backtrace) do |s1|
|
558
558
|
s2 = s1.set(mapper: mapper)
|
559
559
|
old_mapper = s0.fetch(:mapper)
|
560
560
|
|
@@ -563,8 +563,6 @@ module Remap
|
|
563
563
|
s3.return!
|
564
564
|
end.except(:scope).merge(mapper: old_mapper)
|
565
565
|
end
|
566
|
-
|
567
|
-
raise f0.exception(backtrace)
|
568
566
|
end
|
569
567
|
end
|
570
568
|
end
|
data/lib/remap/rule/block.rb
CHANGED
@@ -16,29 +16,23 @@ module Remap
|
|
16
16
|
#
|
17
17
|
# @return [State]
|
18
18
|
def call(state)
|
19
|
-
|
19
|
+
init = state.except(:value)
|
20
20
|
|
21
21
|
if rules.empty?
|
22
|
-
return
|
22
|
+
return init
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
s4 = state.set(fatal_id: fatal_id)
|
25
|
+
catch_fatal(init, backtrace) do |s1, fatal_id:|
|
26
|
+
s2 = state.set(fatal_id: fatal_id)
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
s6 = rule.call(s4)
|
35
|
-
s7 = s6.set(id: id)
|
36
|
-
s5.combine(s7)
|
28
|
+
catch_ignored(s1) do |s3, id:|
|
29
|
+
rules.reduce(s3) do |s4, rule|
|
30
|
+
s5 = rule.call(s2)
|
31
|
+
s6 = s5.set(id: id)
|
32
|
+
s4.combine(s6)
|
37
33
|
end
|
38
|
-
end
|
34
|
+
end
|
39
35
|
end
|
40
|
-
|
41
|
-
raise failure.exception(backtrace)
|
42
36
|
end
|
43
37
|
end
|
44
38
|
end
|
@@ -5,12 +5,14 @@ module Remap
|
|
5
5
|
class Map
|
6
6
|
using State::Extension
|
7
7
|
|
8
|
-
|
8
|
+
# @api private
|
9
|
+
class Optional < Required
|
9
10
|
# Represents an optional mapping rule
|
10
11
|
# When the mapping fails, the value is ignored
|
11
12
|
#
|
12
13
|
# @example Map [:name] to [:nickname]
|
13
14
|
# map = Map::Optional.call({
|
15
|
+
# backtrace: caller,
|
14
16
|
# path: {
|
15
17
|
# input: [:name],
|
16
18
|
# output: [:nickname]
|
@@ -22,16 +24,14 @@ module Remap
|
|
22
24
|
# })
|
23
25
|
#
|
24
26
|
# output = map.call(state) do |failure|
|
25
|
-
# raise failure.
|
27
|
+
# raise failure.exception(caller)
|
26
28
|
# end
|
27
29
|
#
|
28
30
|
# output.fetch(:value) # => { nickname: "John" }
|
29
31
|
#
|
30
|
-
# @
|
31
|
-
#
|
32
|
-
# @return [State]
|
32
|
+
# @see Map#call
|
33
33
|
def call(state)
|
34
|
-
catch_ignored { super(
|
34
|
+
catch_ignored(state) { super(_1) }
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -8,7 +8,19 @@ module Remap
|
|
8
8
|
class Required < Concrete
|
9
9
|
attribute :backtrace, Types::Backtrace
|
10
10
|
|
11
|
-
#
|
11
|
+
# @see Map#call
|
12
|
+
def call(state)
|
13
|
+
catch_fatal(state, backtrace) do |s0|
|
14
|
+
s2 = path.input.call(s0) do |s1|
|
15
|
+
callback(rule.call(s1))
|
16
|
+
end
|
17
|
+
|
18
|
+
s3 = s2.then(&path.output)
|
19
|
+
s4 = s3.set(path: state.path)
|
20
|
+
|
21
|
+
s4.except(:key)
|
22
|
+
end
|
23
|
+
end
|
12
24
|
end
|
13
25
|
end
|
14
26
|
end
|
data/lib/remap/rule/map.rb
CHANGED
@@ -43,29 +43,14 @@ module Remap
|
|
43
43
|
#
|
44
44
|
# @abstract
|
45
45
|
def call(state)
|
46
|
-
|
47
|
-
s0 = state.set(fatal_id: fatal_id)
|
48
|
-
|
49
|
-
s2 = path.input.call(s0) do |s1|
|
50
|
-
s2 = rule.call(s1)
|
51
|
-
callback(s2)
|
52
|
-
end
|
53
|
-
|
54
|
-
s3 = s2.then(&path.output)
|
55
|
-
s4 = s3.set(path: state.path)
|
56
|
-
s5 = s4.except(:key)
|
57
|
-
|
58
|
-
return s5.remove_fatal_id
|
59
|
-
end
|
60
|
-
|
61
|
-
raise failure.exception(backtrace)
|
46
|
+
raise NotImplementedError, "#{self.class}#call not implemented"
|
62
47
|
end
|
63
48
|
|
64
49
|
# A post-processor method
|
65
50
|
#
|
66
51
|
# @example Up-case mapped value
|
67
52
|
# state = Remap::State.call("Hello World")
|
68
|
-
# map = Remap::Rule::Map.call(
|
53
|
+
# map = Remap::Rule::Map.call(backtrace: caller)
|
69
54
|
# upcase = map.adjust(&:upcase)
|
70
55
|
# error = -> failure { raise failure.exception }
|
71
56
|
# upcase.call(state, &error).fetch(:value) # => "HELLO WORLD"
|
@@ -84,7 +69,7 @@ module Remap
|
|
84
69
|
#
|
85
70
|
# @example Pending mapping
|
86
71
|
# state = Remap::State.call(:value)
|
87
|
-
# map = Remap::Rule::Map.call(
|
72
|
+
# map = Remap::Rule::Map::Optional.call(backtrace: caller)
|
88
73
|
# pending = map.pending("this is pending")
|
89
74
|
# error = -> failure { raise failure.exception }
|
90
75
|
# pending.call(state, &error).key?(:value) # => false
|
@@ -99,7 +84,7 @@ module Remap
|
|
99
84
|
# An enumeration processor
|
100
85
|
#
|
101
86
|
# @example A mapped enum
|
102
|
-
# enum = Remap::Rule::Map.call(
|
87
|
+
# enum = Remap::Rule::Map.call(backtrace: caller).enum do
|
103
88
|
# value "A", "B"
|
104
89
|
# otherwise "C"
|
105
90
|
# end
|
@@ -132,7 +117,7 @@ module Remap
|
|
132
117
|
# Keeps map, only if block is true
|
133
118
|
#
|
134
119
|
# @example Keep if value contains "A"
|
135
|
-
# map = Remap::Rule::Map.call(
|
120
|
+
# map = Remap::Rule::Map::Optional.call(backtrace: caller).if do
|
136
121
|
# value.include?("A")
|
137
122
|
# end
|
138
123
|
#
|
@@ -160,11 +145,11 @@ module Remap
|
|
160
145
|
#
|
161
146
|
|
162
147
|
# @example Keep unless value contains "A"
|
163
|
-
# map = Remap::Rule::Map.
|
148
|
+
# map = Remap::Rule::Map::Optional.new(backtrace: caller).if_not do
|
164
149
|
# value.include?("A")
|
165
150
|
# end
|
166
151
|
#
|
167
|
-
# error = -> failure { raise failure.exception }
|
152
|
+
# error = -> failure { raise failure.exception(caller) }
|
168
153
|
#
|
169
154
|
# a = Remap::State.call("A")
|
170
155
|
# map.call(a, &error).key?(:value) # => false
|
@@ -53,7 +53,7 @@ module Remap
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
#
|
56
|
+
# @see #notice
|
57
57
|
def fatal!(...)
|
58
58
|
fatal_id = fetch(:fatal_id) do
|
59
59
|
raise ArgumentError, "Missing :fatal_id in %s" % formatted
|
@@ -62,12 +62,7 @@ module Remap
|
|
62
62
|
throw fatal_id, Failure.new(failures: [notice(...)], notices: notices)
|
63
63
|
end
|
64
64
|
|
65
|
-
#
|
66
|
-
def notice!(...)
|
67
|
-
raise NotImplementedError, "Not implemented"
|
68
|
-
end
|
69
|
-
|
70
|
-
# Throws :ignore containing a Notice
|
65
|
+
# @see #notice
|
71
66
|
def ignore!(...)
|
72
67
|
set(notice: notice(...)).except(:value).return!
|
73
68
|
end
|
@@ -385,6 +380,8 @@ module Remap
|
|
385
380
|
# @return [Failure]
|
386
381
|
def failure(reason = Undefined)
|
387
382
|
failures = case [path, reason]
|
383
|
+
in [_, Undefined]
|
384
|
+
return Failure.new(failures: notices)
|
388
385
|
in [_, Notice => notice]
|
389
386
|
[notice]
|
390
387
|
in [path, Array => reasons]
|