dry-validation 1.5.4 → 1.7.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: e10a66994158c6865c81439277cbbe57a629189cd20257c500658821dd520431
4
- data.tar.gz: 00017e8bc8bf56b4890f5ff441f303556276892681e2c4d732a5ffda52bd54b2
3
+ metadata.gz: 7c1f46e0650eb5f6bf002b5908b561687a709b95234f94dedc113c4b3487673b
4
+ data.tar.gz: 4dbc885bc2b9fca9475f6fd827462a458b99e372dae651686aad3eadee2acfbb
5
5
  SHA512:
6
- metadata.gz: 4dcb6dba84761e057a2bb72e2b4fbd47bba9c568ee0b1bc52e6b5bd48bbd6e7dc804f418746b7d61b9a98fbaede7be075fe6f2b6610209ec934ca8857a1898c4
7
- data.tar.gz: 4a5b3cdd5a6afea0b99a368dc2ce8b244474897692f753e00231b0c77ef4fa7f9ff363b538b1e968ca0a1aa54294efcf0ec44108acaddbcdb1fa267a02ab6b16
6
+ metadata.gz: 11fc47da414268f27ff60c6d0a8bea6fe1a303b94ce5400487f54a7f8f50f33c15b91039d6e6093e61755351a6a7c0dbee7efdbe0f39553f77a7a2201b1dc82d
7
+ data.tar.gz: 6f69f61be289df75425a4bef4956c77c73955f564334f455abbb0e24db7a5713fb80d098d3953093703d79953fc745094805ca7ce4381df1e7b5e720efec7e1a
data/CHANGELOG.md CHANGED
@@ -1,6 +1,57 @@
1
+ <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
+
3
+ ## 1.7.0 2021-09-12
4
+
5
+
6
+ ### Changed
7
+
8
+ - [internal] Upgraded to new `setting` API provided in dry-configurable 0.13.0 (@timriley in #686 and 3f8f7d8)
9
+ - Bumped dry-schema dependency to 1.8.0 (in part, to ensure dry-configurable 0.13.0 is available) (@timriley)
10
+
11
+ [Compare v1.6.0...v1.7.0](https://github.com/dry-rb/dry-validation/compare/v1.6.0...v1.7.0)
12
+
13
+ ## 1.6.0 2020-12-05
14
+
15
+
16
+ ### Added
17
+
18
+ - You can now pass a key name or path to `rule_error?` predicate (issue #658 closed via #673) (@moofkit)
19
+ - You can now pass initial context object to `Contract#call` (issue #674 via #675) (@pyromaniac)
20
+
21
+ ### Fixed
22
+
23
+ - Checking `key?` within a rule no longer crashes when value is `nil` or an empty string (issue #670 fixed via #672) (@alexxty7)
24
+
25
+
26
+ [Compare v1.5.6...v1.6.0](https://github.com/dry-rb/dry-validation/compare/v1.5.6...v1.6.0)
27
+
28
+ ## 1.5.6 2020-09-04
29
+
30
+
31
+ ### Fixed
32
+
33
+ - Dependency on dry-schema was bumped to >= 1.5.1. This time for real (@solnic)
34
+
35
+
36
+ [Compare v1.5.5...v1.5.6](https://github.com/dry-rb/dry-validation/compare/v1.5.5...v1.5.6)
37
+
38
+ ## 1.5.5 2020-09-03
39
+
40
+
41
+ ### Fixed
42
+
43
+ - Dependency on dry-schema was bumped to >= 1.5.2 (see #666 for more info) (@artofhuman)
44
+
45
+
46
+ [Compare v1.5.4...v1.5.5](https://github.com/dry-rb/dry-validation/compare/v1.5.4...v1.5.5)
47
+
1
48
  ## 1.5.4 2020-08-21
2
49
 
3
50
 
51
+ ### Added
52
+
53
+ - You can now pass any key or a path to the rule's `key?` helper (see #664 for more info) (@alassek)
54
+
4
55
  ### Fixed
5
56
 
6
57
  - Full messages work correctly with rule failures now (issue #661 fixed via #662) (@stind)
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2020 dry-rb team
3
+ Copyright (c) 2015-2021 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,3 +1,4 @@
1
+ <!--- this file is synced from dry-rb/template-gem project -->
1
2
  [gem]: https://rubygems.org/gems/dry-validation
2
3
  [actions]: https://github.com/dry-rb/dry-validation/actions
3
4
  [codacy]: https://www.codacy.com/gh/dry-rb/dry-validation
@@ -7,22 +8,22 @@
7
8
  # dry-validation [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
8
9
 
9
10
  [![Gem Version](https://badge.fury.io/rb/dry-validation.svg)][gem]
10
- [![CI Status](https://github.com/dry-rb/dry-validation/workflows/ci/badge.svg)][actions]
11
+ [![CI Status](https://github.com/dry-rb/dry-validation/workflows/CI/badge.svg)][actions]
11
12
  [![Codacy Badge](https://api.codacy.com/project/badge/Grade/f30e3ff5ec304c55a73868cdbf055c67)][codacy]
12
13
  [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/f30e3ff5ec304c55a73868cdbf055c67)][codacy]
13
14
  [![Inline docs](http://inch-ci.org/github/dry-rb/dry-validation.svg?branch=master)][inchpages]
14
15
 
15
16
  ## Links
16
17
 
17
- * [User documentation](http://dry-rb.org/gems/dry-validation)
18
+ * [User documentation](https://dry-rb.org/gems/dry-validation)
18
19
  * [API documentation](http://rubydoc.info/gems/dry-validation)
19
20
 
20
21
  ## Supported Ruby versions
21
22
 
22
23
  This library officially supports the following Ruby versions:
23
24
 
24
- * MRI >= `2.4`
25
- * jruby >= `9.2`
25
+ * MRI `>= 2.6.0`
26
+ * ~~jruby~~ `>= 9.3` (we are waiting for [2.6 support](https://github.com/jruby/jruby/issues/6161))
26
27
 
27
28
  ## License
28
29
 
@@ -1,39 +1,39 @@
1
1
  # frozen_string_literal: true
2
- # this file is managed by dry-rb/devtools project
3
2
 
4
- lib = File.expand_path('lib', __dir__)
3
+ # this file is synced from dry-rb/template-gem project
4
+
5
+ lib = File.expand_path("lib", __dir__)
5
6
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
- require 'dry/validation/version'
7
+ require "dry/validation/version"
7
8
 
8
9
  Gem::Specification.new do |spec|
9
- spec.name = 'dry-validation'
10
+ spec.name = "dry-validation"
10
11
  spec.authors = ["Piotr Solnica"]
11
12
  spec.email = ["piotr.solnica@gmail.com"]
12
- spec.license = 'MIT'
13
+ spec.license = "MIT"
13
14
  spec.version = Dry::Validation::VERSION.dup
14
15
 
15
16
  spec.summary = "Validation library"
16
17
  spec.description = spec.summary
17
- spec.homepage = 'https://dry-rb.org/gems/dry-validation'
18
+ spec.homepage = "https://dry-rb.org/gems/dry-validation"
18
19
  spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-validation.gemspec", "lib/**/*", "config/*.yml"]
19
- spec.bindir = 'bin'
20
+ spec.bindir = "bin"
20
21
  spec.executables = []
21
- spec.require_paths = ['lib']
22
+ spec.require_paths = ["lib"]
22
23
 
23
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
24
- spec.metadata['changelog_uri'] = 'https://github.com/dry-rb/dry-validation/blob/master/CHANGELOG.md'
25
- spec.metadata['source_code_uri'] = 'https://github.com/dry-rb/dry-validation'
26
- spec.metadata['bug_tracker_uri'] = 'https://github.com/dry-rb/dry-validation/issues'
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"
26
+ spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-validation"
27
+ spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-validation/issues"
27
28
 
28
- spec.required_ruby_version = ">= 2.4.0"
29
+ spec.required_ruby_version = ">= 2.6.0"
29
30
 
30
31
  # to update dependencies edit project.yml
31
32
  spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
32
33
  spec.add_runtime_dependency "dry-container", "~> 0.7", ">= 0.7.1"
33
- spec.add_runtime_dependency "dry-core", "~> 0.4"
34
- spec.add_runtime_dependency "dry-equalizer", "~> 0.2"
34
+ spec.add_runtime_dependency "dry-core", "~> 0.5", ">= 0.5"
35
35
  spec.add_runtime_dependency "dry-initializer", "~> 3.0"
36
- spec.add_runtime_dependency "dry-schema", "~> 1.5"
36
+ spec.add_runtime_dependency "dry-schema", "~> 1.8", ">= 1.8.0"
37
37
 
38
38
  spec.add_development_dependency "bundler"
39
39
  spec.add_development_dependency "rake"
@@ -11,7 +11,7 @@ module Dry
11
11
  #
12
12
  # @api public
13
13
  class Config < Schema::Config
14
- setting :macros, Macros::Container.new, &:dup
14
+ setting :macros, default: Macros::Container.new, constructor: :dup.to_proc
15
15
 
16
16
  # @api private
17
17
  def dup
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "concurrent/map"
4
4
 
5
- require "dry/equalizer"
5
+ require "dry/core/equalizer"
6
6
  require "dry/initializer"
7
7
  require "dry/schema/path"
8
8
 
@@ -68,6 +68,11 @@ module Dry
68
68
  # @api public
69
69
  option :macros, default: -> { config.macros }
70
70
 
71
+ # @!attribute [r] default_context
72
+ # @return [Hash] Default context for rules
73
+ # @api public
74
+ option :default_context, default: -> { EMPTY_HASH }
75
+
71
76
  # @!attribute [r] schema
72
77
  # @return [Dry::Schema::Params, Dry::Schema::JSON, Dry::Schema::Processor]
73
78
  # @api private
@@ -86,12 +91,18 @@ module Dry
86
91
  # Apply the contract to an input
87
92
  #
88
93
  # @param [Hash] input The input to validate
94
+ # @param [Hash] context Initial context for rules
89
95
  #
90
96
  # @return [Result]
91
97
  #
92
98
  # @api public
93
- def call(input)
94
- Result.new(schema.(input), Concurrent::Map.new) do |result|
99
+ def call(input, context = EMPTY_HASH)
100
+ context_map = Concurrent::Map.new.tap do |map|
101
+ default_context.each { |key, value| map[key] = value }
102
+ context.each { |key, value| map[key] = value }
103
+ end
104
+
105
+ Result.new(schema.(input), context_map) do |result|
95
106
  rules.each do |rule|
96
107
  next if rule.keys.any? { |key| error?(result, key) }
97
108
 
@@ -187,11 +187,17 @@ module Dry
187
187
 
188
188
  # Check if there are any errors on the current rule
189
189
  #
190
+ # @param path [Symbol, String, Array] A Path-compatible spec
191
+ #
190
192
  # @return [Boolean]
191
193
  #
192
194
  # @api public
193
- def rule_error?
194
- !key(path).empty?
195
+ def rule_error?(path = nil)
196
+ if path.nil?
197
+ !key(self.path).empty?
198
+ else
199
+ result.rule_error?(path)
200
+ end
195
201
  end
196
202
 
197
203
  # @api private
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/equalizer"
3
+ require "dry/core/equalizer"
4
4
 
5
5
  require "dry/schema/constants"
6
6
  require "dry/schema/message"
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "concurrent/map"
4
- require "dry/equalizer"
4
+ require "dry/core/equalizer"
5
5
 
6
6
  require "dry/validation/constants"
7
7
  require "dry/validation/message_set"
@@ -113,6 +113,13 @@ module Dry
113
113
  schema_result.error?(key)
114
114
  end
115
115
 
116
+ # Check if the rules includes an error for the provided key
117
+ #
118
+ # @api private
119
+ def rule_error?(key)
120
+ !schema_error?(key) && error?(key)
121
+ end
122
+
116
123
  # Check if there's any error for the provided key
117
124
  #
118
125
  # This does not consider errors from the nested values
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/equalizer"
3
+ require "dry/core/equalizer"
4
4
 
5
5
  require "dry/validation/constants"
6
6
  require "dry/validation/function"
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/equalizer"
3
+ require "dry/core/equalizer"
4
4
  require "dry/schema/path"
5
5
  require "dry/validation/constants"
6
6
 
@@ -70,6 +70,10 @@ module Dry
70
70
  return result
71
71
  elsif e.is_a?(Symbol) && a.is_a?(Array)
72
72
  return false
73
+ elsif a.nil?
74
+ return false
75
+ elsif a.is_a?(String)
76
+ return false
73
77
  else
74
78
  return false unless a.is_a?(Array) ? (e >= 0 && e < a.size) : a.key?(e)
75
79
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Validation
5
- VERSION = "1.5.4"
5
+ VERSION = "1.7.0"
6
6
  end
7
7
  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.5.4
4
+ version: 1.7.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: 2020-08-21 00:00:00.000000000 Z
11
+ date: 2021-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -50,28 +50,20 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '0.4'
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '0.4'
61
- - !ruby/object:Gem::Dependency
62
- name: dry-equalizer
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - "~>"
53
+ version: '0.5'
54
+ - - ">="
66
55
  - !ruby/object:Gem::Version
67
- version: '0.2'
56
+ version: '0.5'
68
57
  type: :runtime
69
58
  prerelease: false
70
59
  version_requirements: !ruby/object:Gem::Requirement
71
60
  requirements:
72
61
  - - "~>"
73
62
  - !ruby/object:Gem::Version
74
- version: '0.2'
63
+ version: '0.5'
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0.5'
75
67
  - !ruby/object:Gem::Dependency
76
68
  name: dry-initializer
77
69
  requirement: !ruby/object:Gem::Requirement
@@ -92,14 +84,20 @@ dependencies:
92
84
  requirements:
93
85
  - - "~>"
94
86
  - !ruby/object:Gem::Version
95
- version: '1.5'
87
+ version: '1.8'
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 1.8.0
96
91
  type: :runtime
97
92
  prerelease: false
98
93
  version_requirements: !ruby/object:Gem::Requirement
99
94
  requirements:
100
95
  - - "~>"
101
96
  - !ruby/object:Gem::Version
102
- version: '1.5'
97
+ version: '1.8'
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 1.8.0
103
101
  - !ruby/object:Gem::Dependency
104
102
  name: bundler
105
103
  requirement: !ruby/object:Gem::Requirement
@@ -192,14 +190,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
192
190
  requirements:
193
191
  - - ">="
194
192
  - !ruby/object:Gem::Version
195
- version: 2.4.0
193
+ version: 2.6.0
196
194
  required_rubygems_version: !ruby/object:Gem::Requirement
197
195
  requirements:
198
196
  - - ">="
199
197
  - !ruby/object:Gem::Version
200
198
  version: '0'
201
199
  requirements: []
202
- rubygems_version: 3.0.3
200
+ rubygems_version: 3.1.6
203
201
  signing_key:
204
202
  specification_version: 4
205
203
  summary: Validation library