remap 2.2.42 → 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 +23 -5
- data/lib/remap/catchable.rb +31 -10
- data/lib/remap/compiler.rb +2 -4
- data/lib/remap/config.rb +9 -0
- data/lib/remap/extensions/array.rb +2 -0
- data/lib/remap/extensions/hash.rb +1 -1
- data/lib/remap/mapper/and.rb +6 -0
- data/lib/remap/mapper/binary.rb +5 -0
- data/lib/remap/mapper/or.rb +6 -0
- data/lib/remap/mapper/support/api.rb +16 -0
- data/lib/remap/mapper/xor.rb +6 -0
- data/lib/remap/notice/error.rb +0 -21
- data/lib/remap/notice.rb +0 -14
- 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 +11 -7
- data/lib/remap/state/schema.rb +6 -2
- data/lib/remap/types.rb +1 -0
- metadata +3 -2
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
@@ -107,13 +107,12 @@ module Remap
|
|
107
107
|
include ActiveSupport::Configurable
|
108
108
|
include Dry::Core::Constants
|
109
109
|
include Catchable
|
110
|
-
|
111
110
|
extend Mapper::API
|
112
|
-
|
113
111
|
using State::Extension
|
114
112
|
|
115
113
|
with_options instance_accessor: true do |scope|
|
116
114
|
scope.config_accessor(:contract) { Dry::Schema.define {} }
|
115
|
+
scope.config_accessor(:config_options) { Config.new }
|
117
116
|
scope.config_accessor(:constructor) { IDENTITY }
|
118
117
|
scope.config_accessor(:options) { EMPTY_ARRAY }
|
119
118
|
scope.config_accessor(:option) { EMPTY_HASH }
|
@@ -265,6 +264,25 @@ module Remap
|
|
265
264
|
new(state.options).call(state, &error)
|
266
265
|
end
|
267
266
|
|
267
|
+
# Configuration options for the mapper
|
268
|
+
#
|
269
|
+
# @yield [Config]
|
270
|
+
# @yieldreturn [void]
|
271
|
+
#
|
272
|
+
# @return [void]
|
273
|
+
def self.configuration(&block)
|
274
|
+
config = Config.new
|
275
|
+
block[config]
|
276
|
+
self.config_options = config
|
277
|
+
end
|
278
|
+
|
279
|
+
# @see Mapper::API
|
280
|
+
#
|
281
|
+
# @private
|
282
|
+
def self.validate?
|
283
|
+
config_options.validation
|
284
|
+
end
|
285
|
+
|
268
286
|
# Mappers state according to the mapper rules
|
269
287
|
#
|
270
288
|
# @param state [State]
|
@@ -287,11 +305,11 @@ module Remap
|
|
287
305
|
end
|
288
306
|
end
|
289
307
|
|
290
|
-
s1 = catch_ignored do |
|
291
|
-
return context.call(
|
308
|
+
s1 = catch_ignored(state) do |s0|
|
309
|
+
return context.call(s0).then(&constructor).remove_id
|
292
310
|
end
|
293
311
|
|
294
|
-
|
312
|
+
error[s1.failure]
|
295
313
|
end
|
296
314
|
|
297
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/config.rb
ADDED
data/lib/remap/mapper/and.rb
CHANGED
data/lib/remap/mapper/binary.rb
CHANGED
data/lib/remap/mapper/or.rb
CHANGED
@@ -5,6 +5,22 @@ module Remap
|
|
5
5
|
using State::Extension
|
6
6
|
|
7
7
|
module API
|
8
|
+
# @return [Boolean]
|
9
|
+
#
|
10
|
+
# @abstract
|
11
|
+
# @private
|
12
|
+
def validate?
|
13
|
+
raise NotImplementedError, "`validate?` is not implemented for #{self}"
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param input [Any]
|
17
|
+
# @param backtrace [Array<String>]
|
18
|
+
# @param options [Hash]
|
19
|
+
#
|
20
|
+
# @yieldparam [Failure]
|
21
|
+
# @yieldreturn [T]
|
22
|
+
#
|
23
|
+
# @return [Any, T]
|
8
24
|
def call(input, backtrace: caller, **options, &error)
|
9
25
|
unless block_given?
|
10
26
|
return call(input, **options) do |failure|
|
data/lib/remap/mapper/xor.rb
CHANGED
data/lib/remap/notice/error.rb
CHANGED
@@ -11,27 +11,6 @@ module Remap
|
|
11
11
|
delegate_missing_to :notice
|
12
12
|
delegate :inspect, :to_s, to: :notice
|
13
13
|
option :notice, type: Types.Instance(Notice)
|
14
|
-
|
15
|
-
def inspect
|
16
|
-
"#<%s %s>" % [self.class, to_hash.formatted]
|
17
|
-
end
|
18
|
-
|
19
|
-
def undefined(state)
|
20
|
-
state.set(notice: notice).except(:value)
|
21
|
-
end
|
22
|
-
|
23
|
-
def failure(state)
|
24
|
-
Failure.new(failures: [notice], notices: state.fetch(:notices))
|
25
|
-
end
|
26
|
-
|
27
|
-
def traced(backtrace)
|
28
|
-
e = Traced.new(notice: notice)
|
29
|
-
e.set_backtrace(backtrace)
|
30
|
-
e
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class Traced < Error
|
35
14
|
end
|
36
15
|
end
|
37
16
|
end
|
data/lib/remap/notice.rb
CHANGED
@@ -20,19 +20,5 @@ module Remap
|
|
20
20
|
def to_hash
|
21
21
|
super.except(:backtrace).compact_blank
|
22
22
|
end
|
23
|
-
|
24
|
-
# Used by State to skip mapping rules
|
25
|
-
#
|
26
|
-
# @raise [Notice::Ignore]
|
27
|
-
def ignore!
|
28
|
-
raise Ignore.new(notice: self)
|
29
|
-
end
|
30
|
-
|
31
|
-
# Used by the state to halt mappers
|
32
|
-
#
|
33
|
-
# @raise [Notice::Fatal]
|
34
|
-
def fatal!
|
35
|
-
raise Fatal.new(notice: self)
|
36
|
-
end
|
37
23
|
end
|
38
24
|
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
|
-
|
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
|
@@ -92,6 +87,8 @@ module Remap
|
|
92
87
|
#
|
93
88
|
# @return [self]
|
94
89
|
def _(&block)
|
90
|
+
return self unless mapper.validate?
|
91
|
+
|
95
92
|
unless block
|
96
93
|
return _ do |reason|
|
97
94
|
raise ArgumentError, "[BUG] State: #{formatted} reason: #{reason.formatted}"
|
@@ -320,6 +317,11 @@ module Remap
|
|
320
317
|
fetch(:id)
|
321
318
|
end
|
322
319
|
|
320
|
+
# @return [Mapper::API]
|
321
|
+
def mapper
|
322
|
+
fetch(:mapper)
|
323
|
+
end
|
324
|
+
|
323
325
|
# @return [Array<Symbol>]
|
324
326
|
def ids
|
325
327
|
fetch(:ids)
|
@@ -378,6 +380,8 @@ module Remap
|
|
378
380
|
# @return [Failure]
|
379
381
|
def failure(reason = Undefined)
|
380
382
|
failures = case [path, reason]
|
383
|
+
in [_, Undefined]
|
384
|
+
return Failure.new(failures: notices)
|
381
385
|
in [_, Notice => notice]
|
382
386
|
[notice]
|
383
387
|
in [path, Array => reasons]
|
data/lib/remap/state/schema.rb
CHANGED
@@ -9,8 +9,12 @@ module Remap
|
|
9
9
|
required(:notices).array(Types.Instance(Notice))
|
10
10
|
required(:options).value(:hash)
|
11
11
|
required(:path).array(Types::Key)
|
12
|
-
|
13
|
-
required(:
|
12
|
+
|
13
|
+
required(:ids).array(Types::ID)
|
14
|
+
optional(:id).filled(Types::ID)
|
15
|
+
|
16
|
+
required(:fatal_ids).array(Types::ID)
|
17
|
+
optional(:fatal_id).filled(Types::ID)
|
14
18
|
|
15
19
|
optional(:index).filled(:integer)
|
16
20
|
optional(:element).filled
|
data/lib/remap/types.rb
CHANGED
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.
|
4
|
+
version: 2.2.46
|
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-
|
11
|
+
date: 2021-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -251,6 +251,7 @@ files:
|
|
251
251
|
- lib/remap/catchable.rb
|
252
252
|
- lib/remap/class_interface.rb
|
253
253
|
- lib/remap/compiler.rb
|
254
|
+
- lib/remap/config.rb
|
254
255
|
- lib/remap/constructor.rb
|
255
256
|
- lib/remap/constructor/argument.rb
|
256
257
|
- lib/remap/constructor/keyword.rb
|