remap 2.2.42 → 2.2.43

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 791eca1356feec6a254c824130b798026851d4f0e56207b32144ba36f64d06a5
4
- data.tar.gz: f7908a2f3dd0d4847860e342d4f11fa298ba5f9689bf8293d585122993ba40cc
3
+ metadata.gz: 88fc0978315944ad791a089536840916db814b0fc7dad18cda8c19d1c9901d9c
4
+ data.tar.gz: 2b59e22a02ac486b04758c772082731b2e91cb0ba698e40e3502794236515ff5
5
5
  SHA512:
6
- metadata.gz: 7eaed51a433437e884ea6af6485ad81752bfb5c7c388e678794c4e17447311b23aaa32d529451fbb70080617b9654f227fa7ac810d3dbff8e7c9c3e403f8de52
7
- data.tar.gz: 3e14bdd50fa6e3ff3ad77589b969b294161a5878c007b9adba387614c3bcd86300e89ae72d9ea0252739269900757747294b7b89b8e0d2b6ad0ae162d363bd47
6
+ metadata.gz: 41a5d60aa1fa66fb254162d1313611e441e239de54e59c4d7ebaa8a5334a6930317cb32703bd837e85212826b23286afa57e9d8662d8e9c78ab4fc3d569bcddd
7
+ data.tar.gz: 3c8b89c3a3cb5a4fae156a0757b2130afc95ced6911b2707e239e7a3dd791ed5036b46711fb4262b94006b027bc0e98f0882e5a2e4131a12c7730542699e7068
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]
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Remap
4
+ class Config < OpenStruct
5
+ def initialize
6
+ super(validation: false)
7
+ end
8
+ end
9
+ end
@@ -46,6 +46,12 @@ module Remap
46
46
 
47
47
  state1.combine(state2)
48
48
  end
49
+
50
+ # @return [String]
51
+ def inspect
52
+ "%s & %s" % [left, right]
53
+ end
54
+ alias to_s inspect
49
55
  end
50
56
  end
51
57
  end
@@ -8,6 +8,11 @@ module Remap
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
@@ -39,6 +39,12 @@ module Remap
39
39
  end
40
40
  end
41
41
  end
42
+
43
+ # @return [String]
44
+ def inspect
45
+ "%s | %s" % [left, right]
46
+ end
47
+ alias to_s inspect
42
48
  end
43
49
  end
44
50
  end
@@ -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|
@@ -44,6 +44,12 @@ module Remap
44
44
 
45
45
  state1.combine(state2).failure("Both left and right passed xor operation").then(&error)
46
46
  end
47
+
48
+ # @return [String]
49
+ def inspect
50
+ "%s ^ %s" % [left, right]
51
+ end
52
+ alias to_s inspect
47
53
  end
48
54
  end
49
55
  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)
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.42
4
+ version: 2.2.43
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-15 00:00:00.000000000 Z
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