dry-validation 1.8.0 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c0ec5ac402da094ae496a120274c13f2a251300df9b178adb0b688968687082
4
- data.tar.gz: b07231e7542c689d1d02cf2e8de3837592cb7867cc7772c4968034129bb65012
3
+ metadata.gz: fb13f4dba2e8837c0cff3c3d092eacc87c29c367286f6e16f37c4b5d78179066
4
+ data.tar.gz: 66196d258e68914b4546dcc20033e74627f2c738fcbeadbe6d4bfff746861cc0
5
5
  SHA512:
6
- metadata.gz: 7d4835f01c7c8e02d63e1583f6e140efb8db33582800c2c276c94865f6841d8533b91b3fd5832944f57ad8e59f7660dcdff930dfe77e0ae17537c18f0caa14c6
7
- data.tar.gz: e8b2cba4863b18461a8f64e6581654aecaca6525b603e40e6896199faecd5a735f8e5d1a8dbd9d6bb1ac43d562d8bb09ff3bbf77cd01d9b21d9cdef8da4f8e36
6
+ metadata.gz: 1ccea2694b25be64dd68f01c6d9d554c20ae7992ffe78dbf2d483e5d502cdcc2bc3884f567da8d1d303a3b8fa71fa42c85b1a63977c5bef2b42d1496585228f4
7
+ data.tar.gz: e95cd0ce0d5fdcd583b9edb023c1ae6d0797ab5bcfad1816c1a2b9d989c50fea90b66699c89bc5aedeb09483315b8c5d33696cec2e1662e06c7cadff162e9e22
data/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
+ ## 1.9.0 2022-10-15
4
+
5
+
6
+ ### Fixed
7
+
8
+ - Duplicated keys mishandling in rule evaluation (issue #676 fixed via #711) (@mereghost)
9
+
10
+ ### Changed
11
+
12
+ - Use Zeitwerk for auto-loading (via #715) (@solnic)
13
+
14
+ [Compare v1.8.1...v1.9.0](https://github.com/dry-rb/dry-validation/compare/v1.8.1...v1.9.0)
15
+
16
+ ## 1.8.1 2022-05-28
17
+
18
+
19
+ ### Fixed
20
+
21
+ - Raise an InvalidKeyErrors on substring of valid keys (issue #705 fixed via #706) (@MatElGran)
22
+ - Using `rule(:arr).each { .. }` doesn't crash when `:arr` turns out to be `nil` (issue #708 fixed via #709) (@bautrey37)
23
+
24
+
25
+ [Compare v1.8.0...v1.8.1](https://github.com/dry-rb/dry-validation/compare/v1.8.0...v1.8.1)
26
+
3
27
  ## 1.8.0 2022-02-17
4
28
 
5
29
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2021 dry-rb team
3
+ Copyright (c) 2015-2022 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
@@ -11,7 +11,7 @@
11
11
  [![CI Status](https://github.com/dry-rb/dry-validation/workflows/ci/badge.svg)][actions]
12
12
  [![Codacy Badge](https://api.codacy.com/project/badge/Grade/f30e3ff5ec304c55a73868cdbf055c67)][codacy]
13
13
  [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/f30e3ff5ec304c55a73868cdbf055c67)][codacy]
14
- [![Inline docs](http://inch-ci.org/github/dry-rb/dry-validation.svg?branch=master)][inchpages]
14
+ [![Inline docs](http://inch-ci.org/github/dry-rb/dry-validation.svg?branch=main)][inchpages]
15
15
 
16
16
  ## Links
17
17
 
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ["lib"]
23
23
 
24
24
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
25
- spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-validation/blob/master/CHANGELOG.md"
25
+ spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-validation/blob/main/CHANGELOG.md"
26
26
  spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-validation"
27
27
  spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-validation/issues"
28
28
 
@@ -31,9 +31,10 @@ Gem::Specification.new do |spec|
31
31
  # to update dependencies edit project.yml
32
32
  spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
33
33
  spec.add_runtime_dependency "dry-container", "~> 0.7", ">= 0.7.1"
34
- spec.add_runtime_dependency "dry-core", "~> 0.5", ">= 0.5"
34
+ spec.add_runtime_dependency "dry-core", "~> 0.9", ">= 0.9"
35
35
  spec.add_runtime_dependency "dry-initializer", "~> 3.0"
36
- spec.add_runtime_dependency "dry-schema", "~> 1.9", ">= 1.9.1"
36
+ spec.add_runtime_dependency "dry-schema", "~> 1.11", ">= 1.11.0"
37
+ spec.add_runtime_dependency "zeitwerk", "~> 2.6"
37
38
 
38
39
  spec.add_development_dependency "bundler"
39
40
  spec.add_development_dependency "rake"
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/schema/config"
4
- require "dry/validation/macros"
5
-
6
3
  module Dry
7
4
  module Validation
8
5
  # Configuration for contracts
@@ -1,13 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/schema"
4
- require "dry/schema/messages"
5
- require "dry/schema/path"
6
- require "dry/schema/key_map"
7
-
8
3
  require "dry/validation/constants"
9
- require "dry/validation/macros"
10
- require "dry/validation/schema_ext"
11
4
 
12
5
  module Dry
13
6
  module Validation
@@ -158,11 +151,13 @@ module Dry
158
151
  valid_paths = key_map.to_dot_notation
159
152
  key_paths = key_paths(keys)
160
153
 
161
- invalid_keys = key_paths.map { |(key, path)|
162
- unless valid_paths.any? { |vp| vp.include?(path) || vp.include?("#{path}[]") }
154
+ invalid_keys = key_paths.filter_map { |(key, path)|
155
+ if valid_paths.none? { |vp|
156
+ vp == path || vp.start_with?("#{path}.", "#{path}[]")
157
+ }
163
158
  key
164
159
  end
165
- }.compact.uniq
160
+ }.uniq
166
161
 
167
162
  return if invalid_keys.empty?
168
163
 
@@ -2,17 +2,9 @@
2
2
 
3
3
  require "concurrent/map"
4
4
 
5
- require "dry/core/equalizer"
6
5
  require "dry/initializer"
7
- require "dry/schema/path"
8
-
9
- require "dry/validation/config"
10
6
  require "dry/validation/constants"
11
- require "dry/validation/rule"
12
- require "dry/validation/evaluator"
13
- require "dry/validation/messages/resolver"
14
- require "dry/validation/result"
15
- require "dry/validation/contract/class_interface"
7
+ require "dry/validation/schema_ext"
16
8
 
17
9
  module Dry
18
10
  module Validation
@@ -140,8 +132,9 @@ module Dry
140
132
 
141
133
  path
142
134
  .to_a[0..-2]
143
- .any? { |key|
144
- curr_path = Schema::Path[path.keys[0..path.keys.index(key)]]
135
+ .each_with_index
136
+ .any? { |_key, index|
137
+ curr_path = Schema::Path[path.keys[0..index]]
145
138
 
146
139
  return false unless result.schema_error?(curr_path)
147
140
 
@@ -1,10 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "dry/initializer"
4
- require "dry/core/deprecations"
5
-
6
4
  require "dry/validation/constants"
7
- require "dry/validation/failures"
8
5
 
9
6
  module Dry
10
7
  module Validation
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/schema/predicate_registry"
4
- require "dry/validation/contract"
5
-
6
3
  module Dry
7
4
  module Validation
8
5
  # Predicate registry with additional needed methods.
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "dry/validation/constants"
4
- require "dry/validation/function"
5
4
 
6
5
  module Dry
7
6
  module Validation
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "dry/container"
4
- require "dry/validation/macro"
5
4
 
6
5
  module Dry
7
6
  module Validation
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/core/equalizer"
4
-
5
- require "dry/schema/constants"
6
- require "dry/schema/message"
7
-
8
3
  module Dry
9
4
  module Validation
10
5
  # Message message
@@ -1,9 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/schema/message_set"
4
-
5
3
  require "dry/validation/constants"
6
- require "dry/validation/message"
7
4
 
8
5
  module Dry
9
6
  module Validation
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/validation/message"
4
- require "dry/schema/message_compiler"
5
-
6
3
  module Dry
7
4
  module Validation
8
5
  module Messages
@@ -1,11 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "concurrent/map"
4
- require "dry/core/equalizer"
5
4
 
6
5
  require "dry/validation/constants"
7
- require "dry/validation/message_set"
8
- require "dry/validation/values"
9
6
 
10
7
  module Dry
11
8
  module Validation
@@ -1,9 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/core/equalizer"
4
-
5
3
  require "dry/validation/constants"
6
- require "dry/validation/function"
7
4
 
8
5
  module Dry
9
6
  module Validation
@@ -76,13 +73,15 @@ module Dry
76
73
  # @return [Rule]
77
74
  #
78
75
  # @api public
76
+ #
77
+ # rubocop:disable Metrics/AbcSize
79
78
  def each(*macros, &block)
80
79
  root = keys[0]
81
80
  macros = parse_macros(*macros)
82
81
  @keys = []
83
82
 
84
83
  @block = proc do
85
- unless result.base_error?(root) || !values.key?(root)
84
+ unless result.base_error?(root) || !values.key?(root) || values[root].nil?
86
85
  values[root].each_with_index do |_, idx|
87
86
  path = [*Schema::Path[root].to_a, idx]
88
87
 
@@ -99,6 +98,7 @@ module Dry
99
98
 
100
99
  self
101
100
  end
101
+ # rubocop:enable Metrics/AbcSize
102
102
 
103
103
  # Return a nice string representation
104
104
  #
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/core/equalizer"
4
3
  require "dry/schema/path"
5
4
  require "dry/validation/constants"
6
5
 
@@ -65,7 +64,6 @@ module Dry
65
64
  def key?(key, hash = data)
66
65
  return hash.key?(key) if key.is_a?(Symbol)
67
66
 
68
- # rubocop: disable Lint/DuplicateBranch
69
67
  Schema::Path[key].reduce(hash) do |a, e|
70
68
  if e.is_a?(Array)
71
69
  result = e.all? { |k| key?(k, a) }
@@ -81,8 +79,6 @@ module Dry
81
79
  end
82
80
  a[e]
83
81
  end
84
- # rubocop: enable Lint/DuplicateBranch
85
-
86
82
  true
87
83
  end
88
84
  # rubocop: enable Metrics/PerceivedComplexity
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Validation
5
- VERSION = "1.8.0"
5
+ VERSION = "1.9.0"
6
6
  end
7
7
  end
@@ -1,8 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "zeitwerk"
4
+
5
+ require "dry/core"
6
+ require "dry/schema"
7
+
3
8
  require "dry/validation/constants"
4
- require "dry/validation/contract"
5
- require "dry/validation/macros"
6
9
 
7
10
  # Main namespace
8
11
  #
@@ -13,7 +16,22 @@ module Dry
13
16
  # @api public
14
17
  module Validation
15
18
  extend Dry::Core::Extensions
16
- extend Macros::Registrar
19
+
20
+ def self.loader
21
+ @loader ||= Zeitwerk::Loader.new.tap do |loader|
22
+ root = File.expand_path("..", __dir__)
23
+ loader.tag = "dry-validation"
24
+ loader.inflector = Zeitwerk::GemInflector.new("#{root}/dry-validation.rb")
25
+ loader.push_dir(root)
26
+ loader.ignore(
27
+ "#{root}/dry-validation.rb",
28
+ "#{root}/dry/validation/schema_ext.rb",
29
+ "#{root}/dry/validation/{constants,errors,version}.rb",
30
+ "#{root}/dry/validation/extensions"
31
+ )
32
+ loader.inflector.inflect("dsl" => "DSL")
33
+ end
34
+ end
17
35
 
18
36
  register_extension(:monads) do
19
37
  require "dry/validation/extensions/monads"
@@ -56,5 +74,9 @@ module Dry
56
74
  def self.macros
57
75
  Macros
58
76
  end
77
+
78
+ loader.setup
79
+
80
+ extend Macros::Registrar
59
81
  end
60
82
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.9.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-02-17 00:00:00.000000000 Z
11
+ date: 2022-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -50,20 +50,20 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '0.5'
53
+ version: '0.9'
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: '0.5'
56
+ version: '0.9'
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.5'
63
+ version: '0.9'
64
64
  - - ">="
65
65
  - !ruby/object:Gem::Version
66
- version: '0.5'
66
+ version: '0.9'
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: dry-initializer
69
69
  requirement: !ruby/object:Gem::Requirement
@@ -84,20 +84,34 @@ dependencies:
84
84
  requirements:
85
85
  - - "~>"
86
86
  - !ruby/object:Gem::Version
87
- version: '1.9'
87
+ version: '1.11'
88
88
  - - ">="
89
89
  - !ruby/object:Gem::Version
90
- version: 1.9.1
90
+ version: 1.11.0
91
91
  type: :runtime
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '1.9'
97
+ version: '1.11'
98
98
  - - ">="
99
99
  - !ruby/object:Gem::Version
100
- version: 1.9.1
100
+ version: 1.11.0
101
+ - !ruby/object:Gem::Dependency
102
+ name: zeitwerk
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: '2.6'
108
+ type: :runtime
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - "~>"
113
+ - !ruby/object:Gem::Version
114
+ version: '2.6'
101
115
  - !ruby/object:Gem::Dependency
102
116
  name: bundler
103
117
  requirement: !ruby/object:Gem::Requirement
@@ -179,7 +193,7 @@ licenses:
179
193
  - MIT
180
194
  metadata:
181
195
  allowed_push_host: https://rubygems.org
182
- changelog_uri: https://github.com/dry-rb/dry-validation/blob/master/CHANGELOG.md
196
+ changelog_uri: https://github.com/dry-rb/dry-validation/blob/main/CHANGELOG.md
183
197
  source_code_uri: https://github.com/dry-rb/dry-validation
184
198
  bug_tracker_uri: https://github.com/dry-rb/dry-validation/issues
185
199
  post_install_message: