dry-schema 1.12.0 → 1.13.1

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: 7320e83a79df3304ba5bdd03077f15ff7cc57b361070eccce0fe06ffb81794b9
4
- data.tar.gz: c2d39039e5946dc3a587cf984e957d695767629464d38ce8bcf5ce2ac3d5f6f8
3
+ metadata.gz: e1949729f55d95db1df478e3d2bf0077728c2cfaa5a66ac3d6d00bdbaaf55347
4
+ data.tar.gz: 574d9ebd59457187c161730f8b2f232d299ff813fb6af10c680b57ce17c5ee46
5
5
  SHA512:
6
- metadata.gz: 49e56ca6e3db2834008c46fd43e49cbac7f037a57ee58cc43af9ff6c8d992c1573da51bed225e4fc2dd84549b48386f7b335e19c74cc5ed0074ea005709c3695
7
- data.tar.gz: 9401d493d77af5032279b237a5a6da4776eee23414bdb14fa555562362e6f61ffa007304395dda5a45ed3e19b9a31cab989467b7440b1bfb791963771e8f78cc
6
+ metadata.gz: 520e01dc0ab8454bb981fcba032d3a1099fb7fad15b7eaf4008a094fae381178ab389b143a83b2f9f46522722aa14498bcf9a85e9708537d773a3b8f07c81635
7
+ data.tar.gz: 6d3c13d9d1c13dd632368fd4a3ff34aaa8fec5573a5001540552eadd3debe413160d54bbc8051822deb029c9bf20ffe301a120dbd97f2a569eac398de767053e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
+ ## 1.13.1 2023-04-07
4
+
5
+
6
+ ### Fixed
7
+
8
+ - Support sum types of hashes (issue #446 fixed via #457) (@segiddins)
9
+
10
+
11
+ [Compare v1.13.0...v1.13.1](https://github.com/dry-rb/dry-schema/compare/v1.13.0...v1.13.1)
12
+
13
+ ## 1.13.0 2022-11-24
14
+
15
+
16
+ ### Fixed
17
+
18
+ - Change required metadata back to true to fix regressions (issue #438 fixed via 439) (@robhanlon22)
19
+ - Compatibility with dry-configurable 1.0.1 (@flash-gordon)
20
+ - Warnings about using pattern matching on Ruby 2.7 (issue #441 fixed via #442) (@r7kamura)
21
+ - Make message cache fully thread-safe (via #440) (@mensfeld)
22
+
23
+
24
+ [Compare v1.12.0...v1.13.0](https://github.com/dry-rb/dry-schema/compare/v1.12.0...v1.13.0)
25
+
3
26
  ## 1.12.0 2022-11-04
4
27
 
5
28
 
@@ -292,7 +315,7 @@ This release ships with a bunch of internal refactorings that should improve per
292
315
 
293
316
  [Compare v1.5.4...v1.5.5](https://github.com/dry-rb/dry-schema/compare/v1.5.4...v1.5.5)
294
317
 
295
- ## 1.5.4
318
+ ## 1.5.4
296
319
 
297
320
  2020-09-03
298
321
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2022 dry-rb team
3
+ Copyright (c) 2015-2023 dry-rb team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -1,29 +1,21 @@
1
1
  <!--- this file is synced from dry-rb/template-gem project -->
2
2
  [gem]: https://rubygems.org/gems/dry-schema
3
3
  [actions]: https://github.com/dry-rb/dry-schema/actions
4
- [codacy]: https://www.codacy.com/gh/dry-rb/dry-schema
5
- [chat]: https://dry-rb.zulipchat.com
6
- [inchpages]: http://inch-ci.org/github/dry-rb/dry-schema
7
4
 
8
- # dry-schema [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
9
-
10
- [![Gem Version](https://badge.fury.io/rb/dry-schema.svg)][gem]
11
- [![CI Status](https://github.com/dry-rb/dry-schema/workflows/ci/badge.svg)][actions]
12
- [![Codacy Badge](https://api.codacy.com/project/badge/Grade/961f5c776f1d49218b2cede3745e059c)][codacy]
13
- [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/961f5c776f1d49218b2cede3745e059c)][codacy]
14
- [![Inline docs](http://inch-ci.org/github/dry-rb/dry-schema.svg?branch=main)][inchpages]
5
+ # dry-schema [![Gem Version](https://badge.fury.io/rb/dry-schema.svg)][gem] [![CI Status](https://github.com/dry-rb/dry-schema/workflows/ci/badge.svg)][actions]
15
6
 
16
7
  ## Links
17
8
 
18
9
  * [User documentation](https://dry-rb.org/gems/dry-schema)
19
10
  * [API documentation](http://rubydoc.info/gems/dry-schema)
11
+ * [Forum](https://discourse.dry-rb.org)
20
12
 
21
13
  ## Supported Ruby versions
22
14
 
23
15
  This library officially supports the following Ruby versions:
24
16
 
25
- * MRI `>= 2.7.0`
26
- * jruby `>= 9.3` (postponed until 2.7 is supported)
17
+ * MRI `>= 3.0.0`
18
+ * jruby `>= 9.4` (not tested on CI)
27
19
 
28
20
  ## License
29
21
 
data/dry-schema.gemspec CHANGED
@@ -31,16 +31,16 @@ Gem::Specification.new do |spec|
31
31
  spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-schema"
32
32
  spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-schema/issues"
33
33
 
34
- spec.required_ruby_version = ">= 2.7.0"
34
+ spec.required_ruby_version = ">= 2.7"
35
35
 
36
36
  # to update dependencies edit project.yml
37
37
  spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
38
- spec.add_runtime_dependency "zeitwerk", "~> 2.6"
39
- spec.add_runtime_dependency "dry-configurable", "~> 1.0", "< 2"
38
+ spec.add_runtime_dependency "dry-configurable", "~> 1.0", ">= 1.0.1"
40
39
  spec.add_runtime_dependency "dry-core", "~> 1.0", "< 2"
41
40
  spec.add_runtime_dependency "dry-initializer", "~> 3.0"
42
41
  spec.add_runtime_dependency "dry-logic", ">= 1.4", "< 2"
43
42
  spec.add_runtime_dependency "dry-types", ">= 1.7", "< 2"
43
+ spec.add_runtime_dependency "zeitwerk", "~> 2.6"
44
44
 
45
45
  spec.add_development_dependency "bundler"
46
46
  spec.add_development_dependency "rake"
@@ -293,8 +293,8 @@ module Dry
293
293
  # @return [Dry::Types::Safe]
294
294
  #
295
295
  # @api private
296
- def new(**options, &block)
297
- self.class.new(**options, processor_type: processor_type, config: config, &block)
296
+ def new(klass: self.class, **options, &block)
297
+ klass.new(**options, processor_type: processor_type, config: config, &block)
298
298
  end
299
299
 
300
300
  # Set a type for the given key name
@@ -307,7 +307,7 @@ module Dry
307
307
  # @api private
308
308
  def set_type(name, spec)
309
309
  type = resolve_type(spec)
310
- meta = {required: true, maybe: type.optional?}
310
+ meta = {required: false, maybe: type.optional?}
311
311
 
312
312
  @types[name] = type.meta(meta)
313
313
  end
@@ -122,7 +122,6 @@ module Dry
122
122
  macro.call(...)
123
123
  end
124
124
  end
125
- ruby2_keywords :schema if respond_to?(:ruby2_keywords, true)
126
125
 
127
126
  # Specify a nested hash with enforced `hash?` type-check
128
127
  #
@@ -137,7 +136,6 @@ module Dry
137
136
  macro.call(...)
138
137
  end
139
138
  end
140
- ruby2_keywords :hash if respond_to?(:ruby2_keywords, true)
141
139
 
142
140
  # Specify predicates that should be applied to each element of an array
143
141
  #
@@ -161,7 +159,6 @@ module Dry
161
159
  macro.value(...)
162
160
  end
163
161
  end
164
- ruby2_keywords :each if respond_to?(:ruby2_keywords, true)
165
162
 
166
163
  # Like `each` but sets `array?` type-check
167
164
  #
@@ -181,7 +178,6 @@ module Dry
181
178
  macro.value(...)
182
179
  end
183
180
  end
184
- ruby2_keywords :array if respond_to?(:ruby2_keywords, true)
185
181
 
186
182
  # Set type spec
187
183
  #
@@ -220,6 +216,8 @@ module Dry
220
216
  end
221
217
 
222
218
  # @api private
219
+ # rubocop: disable Metrics/AbcSize
220
+ # rubocop: disable Metrics/CyclomaticComplexity
223
221
  # rubocop: disable Metrics/PerceivedComplexity
224
222
  def extract_type_spec(args, nullable: false, set_type: true)
225
223
  type_spec = args[0] unless schema_or_predicate?(args[0])
@@ -232,6 +230,10 @@ module Dry
232
230
 
233
231
  if type_spec.is_a?(::Array)
234
232
  type_rule = type_spec.map { |ts| new(chain: false).value(ts) }.reduce(:|)
233
+ elsif type_spec.is_a?(Dry::Types::Sum) && set_type
234
+ type_rule = [type_spec.left, type_spec.right].map { |ts|
235
+ new(klass: Core, chain: false).value(ts)
236
+ }.reduce(:|)
235
237
  else
236
238
  type_predicates = predicate_inferrer[resolved_type]
237
239
 
@@ -249,6 +251,8 @@ module Dry
249
251
  yield(*predicates, type_spec: type_spec, type_rule: nil)
250
252
  end
251
253
  end
254
+ # rubocop: enable Metrics/AbcSize
255
+ # rubocop: enable Metrics/CyclomaticComplexity
252
256
  # rubocop: enable Metrics/PerceivedComplexity
253
257
 
254
258
  # @api private
@@ -26,7 +26,6 @@ module Dry
26
26
  (filter_schema_dsl[name] || filter_schema_dsl.optional(name)).value(...)
27
27
  self
28
28
  end
29
- ruby2_keywords(:filter) if respond_to?(:ruby2_keywords, true)
30
29
 
31
30
  # Coerce macro to a rule
32
31
  #
@@ -45,13 +45,7 @@ module Dry
45
45
 
46
46
  # @api private
47
47
  def self.setting_names
48
- # TODO: this is compatibility tweak to make it work with dry-configurable < 0.16.1
49
- # and should be removed in dry-schema 2.0.0
50
- @setting_names ||= settings
51
- .map { |setting|
52
- setting.respond_to?(:name) ? setting.name : setting
53
- }
54
- .map(&:to_sym)
48
+ @setting_names ||= settings.map { _1.name.to_sym }
55
49
  end
56
50
 
57
51
  # @api private
@@ -13,7 +13,7 @@ module Dry
13
13
  # @api public
14
14
  class YAML < Abstract
15
15
  LOCALE_TOKEN = "%<locale>s"
16
- TOKEN_REGEXP = /%{(\w*)}/.freeze
16
+ TOKEN_REGEXP = /%{(\w*)}/
17
17
  EMPTY_CONTEXT = Object.new.tap { |ctx|
18
18
  def ctx.context
19
19
  binding
@@ -70,7 +70,9 @@ module Dry
70
70
 
71
71
  # @api private
72
72
  def self.cache
73
- @cache ||= Concurrent::Map.new { |h, k| h[k] = Concurrent::Map.new }
73
+ @cache ||= Concurrent::Map.new do |h, k|
74
+ h.compute_if_absent(k) { Concurrent::Map.new }
75
+ end
74
76
  end
75
77
 
76
78
  # @api private
@@ -82,7 +84,7 @@ module Dry
82
84
  def initialize(data: EMPTY_HASH, config: nil)
83
85
  super()
84
86
  @data = data
85
- @config = config if config
87
+ @__config__ = config if config
86
88
  @t = proc { |key, locale: default_locale| get("%<locale>s.#{key}", locale: locale) }
87
89
  end
88
90
 
@@ -46,6 +46,9 @@ module Dry
46
46
  # @api private
47
47
  attr_reader :args
48
48
 
49
+ # @api private
50
+ attr_reader :arity
51
+
49
52
  # @api private
50
53
  attr_reader :block
51
54
 
@@ -55,6 +58,8 @@ module Dry
55
58
  @name = name
56
59
  @args = args
57
60
  @block = block
61
+ # Cater for optional second argument like in case of `eql?` or `respond_to?`
62
+ @arity = compiler.predicates[name].arity.abs
58
63
  end
59
64
 
60
65
  # Negate a predicate
@@ -71,7 +76,7 @@ module Dry
71
76
 
72
77
  # @api private
73
78
  def ensure_valid
74
- if compiler.predicates[name].arity - 1 != args.size
79
+ if arity - 1 != args.size
75
80
  raise ArgumentError, "#{name} predicate arity is invalid"
76
81
  end
77
82
  end
@@ -9,11 +9,13 @@ module Dry
9
9
  # @api private
10
10
  def arg_list(name, *values)
11
11
  predicate = self[name]
12
+ # Cater for optional second argument like in case of `eql?` or `respond_to?`
13
+ arity = predicate.arity.abs
12
14
 
13
15
  predicate
14
16
  .parameters
15
17
  .map(&:last)
16
- .zip(values + Array.new(predicate.arity - values.size, Undefined))
18
+ .zip(values + Array.new(arity - values.size, Undefined))
17
19
  end
18
20
  end
19
21
  end
@@ -72,6 +72,8 @@ module Dry
72
72
  # Dump result to a hash returning processed and validated data
73
73
  #
74
74
  # @return [Hash]
75
+ #
76
+ # @api private
75
77
  def output
76
78
  path.equal?(Path::EMPTY) ? @output : @output.dig(*path)
77
79
  end
@@ -66,17 +66,61 @@ module Dry
66
66
  alias_method :merge_and, :merge_ordered
67
67
  alias_method :merge_implication, :merge_ordered
68
68
 
69
- # @api private
70
- def merge_unwrapped_types(unwrapped_old, unwrapped_new)
71
- case [unwrapped_old, unwrapped_new]
72
- in Dry::Types::Schema, Dry::Types::Schema
73
- merge_schemas(unwrapped_old, unwrapped_new)
74
- in [Dry::Types::AnyClass, _] | [Dry::Types::Hash, Dry::Types::Schema]
75
- unwrapped_new
76
- in [Dry::Types::Schema, Dry::Types::Hash] | [_, Dry::Types::AnyClass]
77
- unwrapped_old
78
- else
79
- merge_equivalent_types(unwrapped_old, unwrapped_new)
69
+ if RUBY_VERSION >= "3.0"
70
+ class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
71
+ # @api private
72
+ def merge_unwrapped_types(unwrapped_old, unwrapped_new)
73
+ case [unwrapped_old, unwrapped_new]
74
+ in Dry::Types::Schema, Dry::Types::Schema
75
+ merge_schemas(unwrapped_old, unwrapped_new)
76
+ in [Dry::Types::AnyClass, _] | [Dry::Types::Hash, Dry::Types::Schema]
77
+ unwrapped_new
78
+ in [Dry::Types::Schema, Dry::Types::Hash] | [_, Dry::Types::AnyClass]
79
+ unwrapped_old
80
+ else
81
+ merge_equivalent_types(unwrapped_old, unwrapped_new)
82
+ end
83
+ end
84
+ RUBY
85
+ else
86
+ # @api private
87
+ def merge_unwrapped_types(unwrapped_old, unwrapped_new)
88
+ if change_from_schema_to_schema?(unwrapped_old, unwrapped_new)
89
+ merge_schemas(unwrapped_old, unwrapped_new)
90
+ elsif change_from_any?(unwrapped_old) || change_from_hash_to_schema?(unwrapped_old,
91
+ unwrapped_new)
92
+ unwrapped_new
93
+ elsif change_from_schema_to_hash?(unwrapped_old,
94
+ unwrapped_new) || change_to_any?(unwrapped_new)
95
+ unwrapped_old
96
+ else
97
+ merge_equivalent_types(unwrapped_old, unwrapped_new)
98
+ end
99
+ end
100
+
101
+ # @api private
102
+ def change_from_any?(unwrapped_old)
103
+ unwrapped_old.is_a?(Dry::Types::AnyClass)
104
+ end
105
+
106
+ # @api private
107
+ def change_to_any?(unwrapped_new)
108
+ unwrapped_new.is_a?(Dry::Types::AnyClass)
109
+ end
110
+
111
+ # @api private
112
+ def change_from_hash_to_schema?(unwrapped_old, unwrapped_new)
113
+ unwrapped_old.is_a?(Dry::Types::Hash) && unwrapped_new.is_a?(Dry::Types::Schema)
114
+ end
115
+
116
+ # @api private
117
+ def change_from_schema_to_hash?(unwrapped_old, unwrapped_new)
118
+ unwrapped_old.is_a?(Dry::Types::Schema) && unwrapped_new.is_a?(Dry::Types::Hash)
119
+ end
120
+
121
+ # @api private
122
+ def change_from_schema_to_schema?(unwrapped_old, unwrapped_new)
123
+ unwrapped_old.is_a?(Dry::Types::Schema) && unwrapped_new.is_a?(Dry::Types::Schema)
80
124
  end
81
125
  end
82
126
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Schema
5
- VERSION = "1.12.0"
5
+ VERSION = "1.13.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.0
4
+ version: 1.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-04 00:00:00.000000000 Z
11
+ date: 2023-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
- - !ruby/object:Gem::Dependency
28
- name: zeitwerk
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '2.6'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '2.6'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: dry-configurable
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -45,9 +31,9 @@ dependencies:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
33
  version: '1.0'
48
- - - "<"
34
+ - - ">="
49
35
  - !ruby/object:Gem::Version
50
- version: '2'
36
+ version: 1.0.1
51
37
  type: :runtime
52
38
  prerelease: false
53
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -55,9 +41,9 @@ dependencies:
55
41
  - - "~>"
56
42
  - !ruby/object:Gem::Version
57
43
  version: '1.0'
58
- - - "<"
44
+ - - ">="
59
45
  - !ruby/object:Gem::Version
60
- version: '2'
46
+ version: 1.0.1
61
47
  - !ruby/object:Gem::Dependency
62
48
  name: dry-core
63
49
  requirement: !ruby/object:Gem::Requirement
@@ -132,6 +118,20 @@ dependencies:
132
118
  - - "<"
133
119
  - !ruby/object:Gem::Version
134
120
  version: '2'
121
+ - !ruby/object:Gem::Dependency
122
+ name: zeitwerk
123
+ requirement: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - "~>"
126
+ - !ruby/object:Gem::Version
127
+ version: '2.6'
128
+ type: :runtime
129
+ prerelease: false
130
+ version_requirements: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - "~>"
133
+ - !ruby/object:Gem::Version
134
+ version: '2.6'
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: bundler
137
137
  requirement: !ruby/object:Gem::Requirement
@@ -274,14 +274,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
274
274
  requirements:
275
275
  - - ">="
276
276
  - !ruby/object:Gem::Version
277
- version: 2.7.0
277
+ version: '2.7'
278
278
  required_rubygems_version: !ruby/object:Gem::Requirement
279
279
  requirements:
280
280
  - - ">="
281
281
  - !ruby/object:Gem::Version
282
282
  version: '0'
283
283
  requirements: []
284
- rubygems_version: 3.1.6
284
+ rubygems_version: 3.3.26
285
285
  signing_key:
286
286
  specification_version: 4
287
287
  summary: Coercion and validation for data structures