dry-schema 1.11.3 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/README.md +2 -10
- data/dry-schema.gemspec +4 -4
- data/lib/dry/schema/dsl.rb +1 -1
- data/lib/dry/schema/messages/abstract.rb +1 -7
- data/lib/dry/schema/messages/yaml.rb +4 -2
- data/lib/dry/schema/predicate.rb +6 -1
- data/lib/dry/schema/predicate_registry.rb +3 -1
- data/lib/dry/schema/type_container.rb +2 -2
- data/lib/dry/schema/types_merger.rb +55 -11
- data/lib/dry/schema/version.rb +1 -1
- metadata +32 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9899c8cf36335581b0f5f757c5a2c17d7a542b47138eb6f76dd1f8bda8ed3c65
|
4
|
+
data.tar.gz: 1d10a271359578fb471a6e6fd477e690f4b11888b936f92242b51c2d143b8f36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6156af8cad80db7b37a2062079053cddd8d40195d50d2d0db119c4163be1c8105855a1b61bd29de82cd8ee8e96a2329c4346139190d560a8b5c858cf7401b12
|
7
|
+
data.tar.gz: 9bcdbb0a8feb2127bd170036904007ddc3ec6228b8a888f868e70eb3055aac718ffd5d4ee5734a10618efa545f4ea0bcb102bf760db16fe47049bac57c65b48e
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,27 @@
|
|
1
1
|
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
+
## 1.13.0 2022-11-24
|
4
|
+
|
5
|
+
|
6
|
+
### Fixed
|
7
|
+
|
8
|
+
- Change required metadata back to true to fix regressions (issue #438 fixed via 439) (@robhanlon22)
|
9
|
+
- Compatibility with dry-configurable 1.0.1 (@flash-gordon)
|
10
|
+
- Warnings about using pattern matching on Ruby 2.7 (issue #441 fixed via #442) (@r7kamura)
|
11
|
+
- Make message cache fully thread-safe (via #440) (@mensfeld)
|
12
|
+
|
13
|
+
|
14
|
+
[Compare v1.12.0...v1.13.0](https://github.com/dry-rb/dry-schema/compare/v1.12.0...v1.13.0)
|
15
|
+
|
16
|
+
## 1.12.0 2022-11-04
|
17
|
+
|
18
|
+
|
19
|
+
### Changed
|
20
|
+
|
21
|
+
- This version depends on dry-core 1.0 and dry-configurable 1.0 (@flash-gordon)
|
22
|
+
|
23
|
+
[Compare v1.11.3...v1.12.0](https://github.com/dry-rb/dry-schema/compare/v1.11.3...v1.12.0)
|
24
|
+
|
3
25
|
## 1.11.3 2022-10-21
|
4
26
|
|
5
27
|
|
data/README.md
CHANGED
@@ -1,22 +1,14 @@
|
|
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 [![
|
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
|
|
data/dry-schema.gemspec
CHANGED
@@ -35,11 +35,11 @@ Gem::Specification.new do |spec|
|
|
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 "dry-configurable", "~> 0
|
39
|
-
spec.add_runtime_dependency "dry-core", "~> 0
|
38
|
+
spec.add_runtime_dependency "dry-configurable", "~> 1.0", ">= 1.0.1"
|
39
|
+
spec.add_runtime_dependency "dry-core", "~> 1.0", "< 2"
|
40
40
|
spec.add_runtime_dependency "dry-initializer", "~> 3.0"
|
41
|
-
spec.add_runtime_dependency "dry-logic", "
|
42
|
-
spec.add_runtime_dependency "dry-types", "
|
41
|
+
spec.add_runtime_dependency "dry-logic", ">= 1.5", "< 2"
|
42
|
+
spec.add_runtime_dependency "dry-types", ">= 1.7", "< 2"
|
43
43
|
spec.add_runtime_dependency "zeitwerk", "~> 2.6"
|
44
44
|
|
45
45
|
spec.add_development_dependency "bundler"
|
data/lib/dry/schema/dsl.rb
CHANGED
@@ -45,13 +45,7 @@ module Dry
|
|
45
45
|
|
46
46
|
# @api private
|
47
47
|
def self.setting_names
|
48
|
-
|
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
|
@@ -70,7 +70,9 @@ module Dry
|
|
70
70
|
|
71
71
|
# @api private
|
72
72
|
def self.cache
|
73
|
-
@cache ||= 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
|
-
@
|
87
|
+
@__config__ = config if config
|
86
88
|
@t = proc { |key, locale: default_locale| get("%<locale>s.#{key}", locale: locale) }
|
87
89
|
end
|
88
90
|
|
data/lib/dry/schema/predicate.rb
CHANGED
@@ -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
|
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(
|
18
|
+
.zip(values + Array.new(arity - values.size, Undefined))
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "dry/container"
|
3
|
+
require "dry/core/container"
|
4
4
|
require "dry/types"
|
5
5
|
|
6
6
|
module Dry
|
@@ -13,7 +13,7 @@ module Dry
|
|
13
13
|
#
|
14
14
|
# @api public
|
15
15
|
class TypeContainer
|
16
|
-
include Dry::Container::Mixin
|
16
|
+
include Dry::Core::Container::Mixin
|
17
17
|
|
18
18
|
def initialize(types_container = Dry::Types.container)
|
19
19
|
super()
|
@@ -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
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
|
data/lib/dry/schema/version.rb
CHANGED
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.
|
4
|
+
version: 1.13.0
|
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
|
+
date: 2022-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -30,40 +30,40 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0
|
33
|
+
version: '1.0'
|
34
34
|
- - ">="
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
36
|
+
version: 1.0.1
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
41
|
- - "~>"
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: '0
|
43
|
+
version: '1.0'
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
46
|
+
version: 1.0.1
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: dry-core
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0
|
54
|
-
- - "
|
53
|
+
version: '1.0'
|
54
|
+
- - "<"
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: '
|
56
|
+
version: '2'
|
57
57
|
type: :runtime
|
58
58
|
prerelease: false
|
59
59
|
version_requirements: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
61
|
- - "~>"
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version: '0
|
64
|
-
- - "
|
63
|
+
version: '1.0'
|
64
|
+
- - "<"
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: '
|
66
|
+
version: '2'
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
name: dry-initializer
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,30 +82,42 @@ dependencies:
|
|
82
82
|
name: dry-logic
|
83
83
|
requirement: !ruby/object:Gem::Requirement
|
84
84
|
requirements:
|
85
|
-
- - "
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '1.5'
|
88
|
+
- - "<"
|
86
89
|
- !ruby/object:Gem::Version
|
87
|
-
version: '
|
90
|
+
version: '2'
|
88
91
|
type: :runtime
|
89
92
|
prerelease: false
|
90
93
|
version_requirements: !ruby/object:Gem::Requirement
|
91
94
|
requirements:
|
92
|
-
- - "
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '1.5'
|
98
|
+
- - "<"
|
93
99
|
- !ruby/object:Gem::Version
|
94
|
-
version: '
|
100
|
+
version: '2'
|
95
101
|
- !ruby/object:Gem::Dependency
|
96
102
|
name: dry-types
|
97
103
|
requirement: !ruby/object:Gem::Requirement
|
98
104
|
requirements:
|
99
|
-
- - "
|
105
|
+
- - ">="
|
100
106
|
- !ruby/object:Gem::Version
|
101
|
-
version: '1.
|
107
|
+
version: '1.7'
|
108
|
+
- - "<"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2'
|
102
111
|
type: :runtime
|
103
112
|
prerelease: false
|
104
113
|
version_requirements: !ruby/object:Gem::Requirement
|
105
114
|
requirements:
|
106
|
-
- - "
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.7'
|
118
|
+
- - "<"
|
107
119
|
- !ruby/object:Gem::Version
|
108
|
-
version: '
|
120
|
+
version: '2'
|
109
121
|
- !ruby/object:Gem::Dependency
|
110
122
|
name: zeitwerk
|
111
123
|
requirement: !ruby/object:Gem::Requirement
|