remap 2.2.41 → 2.2.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/remap/base.rb +21 -27
- 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 +6 -1
- data/lib/remap/mapper/or.rb +6 -0
- data/lib/remap/mapper/support/api.rb +48 -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/map/optional.rb +1 -1
- data/lib/remap/state/extension.rb +7 -0
- data/lib/remap/state/schema.rb +6 -2
- data/lib/remap/types.rb +1 -0
- data/lib/remap.rb +1 -0
- metadata +4 -3
- data/lib/remap/operation.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd36dff737c5c3965b1a7bc5dd643bc83098a908c7dac7426a13e6c40a76af95
|
4
|
+
data.tar.gz: 958e0d19bc7d57a72697af4c1dea86f47810f87025a99ab1e13824f82822ce53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62e4ad82b773e57a113f190ab5cb3d238e9e0059aa4f692475c8372c91ed25dc9c564782a0522cb1902c2d5f408f0109136487ceb6176bfd5e0e4dd3b92cba23
|
7
|
+
data.tar.gz: 647d4ee1c543073752b92d4e04a7deadde0dd4522ae793cf475544f58a88986d9077bf44fcb2b3cf0acf2b9ee7d5400ff4c95d246f05b78f9e9ce62c800e0c2f
|
data/lib/remap/base.rb
CHANGED
@@ -106,13 +106,13 @@ module Remap
|
|
106
106
|
class Base < Mapper
|
107
107
|
include ActiveSupport::Configurable
|
108
108
|
include Dry::Core::Constants
|
109
|
-
|
110
109
|
include Catchable
|
111
|
-
|
110
|
+
extend Mapper::API
|
112
111
|
using State::Extension
|
113
112
|
|
114
113
|
with_options instance_accessor: true do |scope|
|
115
114
|
scope.config_accessor(:contract) { Dry::Schema.define {} }
|
115
|
+
scope.config_accessor(:config_options) { Config.new }
|
116
116
|
scope.config_accessor(:constructor) { IDENTITY }
|
117
117
|
scope.config_accessor(:options) { EMPTY_ARRAY }
|
118
118
|
scope.config_accessor(:option) { EMPTY_HASH }
|
@@ -122,31 +122,6 @@ module Remap
|
|
122
122
|
|
123
123
|
schema schema.strict(false)
|
124
124
|
|
125
|
-
# extend Operation
|
126
|
-
|
127
|
-
def self.call(input, backtrace: caller, **options, &error)
|
128
|
-
unless block_given?
|
129
|
-
return call(input, **options) do |failure|
|
130
|
-
raise failure.exception(backtrace)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
s0 = State.call(input, options: options, mapper: self)._
|
135
|
-
|
136
|
-
s1 = call!(s0) do |failure|
|
137
|
-
return error[failure]
|
138
|
-
end
|
139
|
-
|
140
|
-
case s1
|
141
|
-
in { value: value }
|
142
|
-
value
|
143
|
-
in { notices: [] }
|
144
|
-
error[s1.failure("No data could be mapped")]
|
145
|
-
in { notices: }
|
146
|
-
error[Failure.new(failures: notices)]
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
125
|
# Defines a schema for the mapper
|
151
126
|
# If the schema fail, the mapper will fail
|
152
127
|
#
|
@@ -289,6 +264,25 @@ module Remap
|
|
289
264
|
new(state.options).call(state, &error)
|
290
265
|
end
|
291
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
|
+
|
292
286
|
# Mappers state according to the mapper rules
|
293
287
|
#
|
294
288
|
# @param state [State]
|
data/lib/remap/config.rb
ADDED
data/lib/remap/mapper/and.rb
CHANGED
data/lib/remap/mapper/binary.rb
CHANGED
@@ -4,10 +4,15 @@ module Remap
|
|
4
4
|
class Mapper
|
5
5
|
# @abstract
|
6
6
|
class Binary < self
|
7
|
-
include
|
7
|
+
include API
|
8
8
|
|
9
9
|
attribute :left, Types::Mapper
|
10
10
|
attribute :right, Types::Mapper
|
11
|
+
|
12
|
+
# @return [Bool]
|
13
|
+
def validate?
|
14
|
+
left.validate? && right.validate?
|
15
|
+
end
|
11
16
|
end
|
12
17
|
end
|
13
18
|
end
|
data/lib/remap/mapper/or.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Remap
|
4
|
+
class Mapper
|
5
|
+
using State::Extension
|
6
|
+
|
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]
|
24
|
+
def call(input, backtrace: caller, **options, &error)
|
25
|
+
unless block_given?
|
26
|
+
return call(input, **options) do |failure|
|
27
|
+
raise failure.exception(backtrace)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
s0 = State.call(input, options: options, mapper: self)._
|
32
|
+
|
33
|
+
s1 = call!(s0) do |failure|
|
34
|
+
return error[failure]
|
35
|
+
end
|
36
|
+
|
37
|
+
case s1
|
38
|
+
in { value: value }
|
39
|
+
value
|
40
|
+
in { notices: [] }
|
41
|
+
error[s1.failure("No data could be mapped")]
|
42
|
+
in { notices: }
|
43
|
+
error[Failure.new(failures: notices)]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
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
|
@@ -92,6 +92,8 @@ module Remap
|
|
92
92
|
#
|
93
93
|
# @return [self]
|
94
94
|
def _(&block)
|
95
|
+
return self unless mapper.validate?
|
96
|
+
|
95
97
|
unless block
|
96
98
|
return _ do |reason|
|
97
99
|
raise ArgumentError, "[BUG] State: #{formatted} reason: #{reason.formatted}"
|
@@ -320,6 +322,11 @@ module Remap
|
|
320
322
|
fetch(:id)
|
321
323
|
end
|
322
324
|
|
325
|
+
# @return [Mapper::API]
|
326
|
+
def mapper
|
327
|
+
fetch(:mapper)
|
328
|
+
end
|
329
|
+
|
323
330
|
# @return [Array<Symbol>]
|
324
331
|
def ids
|
325
332
|
fetch(:ids)
|
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
data/lib/remap.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.45
|
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
|
@@ -271,6 +272,7 @@ files:
|
|
271
272
|
- lib/remap/mapper/and.rb
|
272
273
|
- lib/remap/mapper/binary.rb
|
273
274
|
- lib/remap/mapper/or.rb
|
275
|
+
- lib/remap/mapper/support/api.rb
|
274
276
|
- lib/remap/mapper/support/operations.rb
|
275
277
|
- lib/remap/mapper/xor.rb
|
276
278
|
- lib/remap/nothing.rb
|
@@ -278,7 +280,6 @@ files:
|
|
278
280
|
- lib/remap/notice/error.rb
|
279
281
|
- lib/remap/notice/fatal.rb
|
280
282
|
- lib/remap/notice/ignore.rb
|
281
|
-
- lib/remap/operation.rb
|
282
283
|
- lib/remap/path.rb
|
283
284
|
- lib/remap/path/input.rb
|
284
285
|
- lib/remap/path/output.rb
|
data/lib/remap/operation.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Remap
|
4
|
-
using State::Extension
|
5
|
-
|
6
|
-
# Class interface for {Remap::Base} and instance interface for {Mapper}
|
7
|
-
module Operation
|
8
|
-
# Public interface for mappers
|
9
|
-
#
|
10
|
-
# @param input [Any] data to be mapped
|
11
|
-
# @param options [Hash] mapper options
|
12
|
-
#
|
13
|
-
# @yield [Failure]
|
14
|
-
# when a non-critical error occurs
|
15
|
-
# @yieldreturn T
|
16
|
-
#
|
17
|
-
# @return [Any, T]
|
18
|
-
# when request is a success
|
19
|
-
# @raise [Remap::Error]
|
20
|
-
# when a fatal error occurs
|
21
|
-
def call(input, backtrace: caller, **options, &error)
|
22
|
-
unless block_given?
|
23
|
-
return call(input, **options) do |failure|
|
24
|
-
raise failure.exception(backtrace)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
s0 = State.call(input, options: options, mapper: self)._
|
29
|
-
|
30
|
-
s1 = call!(s0) do |failure|
|
31
|
-
return error[failure]
|
32
|
-
end
|
33
|
-
|
34
|
-
case s1
|
35
|
-
in { value: value }
|
36
|
-
value
|
37
|
-
in { notices: [] }
|
38
|
-
error[s1.failure("No data could be mapped")]
|
39
|
-
in { notices: }
|
40
|
-
error[Failure.new(failures: notices)]
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|