dry-schema 1.5.4 → 1.6.2

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: c6bd0ccbd94f361dc0e001b71fc4d1dbd76d00605a4d57c7e6fe06788235c0f0
4
- data.tar.gz: 29b3eb25a1ede9775dd331752a6abc51d2fd617764e14611899e8b07fb6f7ee8
3
+ metadata.gz: ad4d59e0bdc2cc46cc165f50e1ab741c07d1c00dca7467c4a6bfd647460a6d3b
4
+ data.tar.gz: 295466e7e905103612280d5fdb549f116212c99c2c96b54f3561b1264174a499
5
5
  SHA512:
6
- metadata.gz: 96f5e58a3ae138e6461d33e7e2bd030655191a6f8132c0d5adada3195d35f03b011b94d79c085fe0567a299caf63859349948ee0d8e06b73ac0a7a480f6d2db9
7
- data.tar.gz: c89a7b623c5ac5fc1cad6b880a4c02b892af9efad76c99e7803b0e0115a26445cf1d35d1bba4518f0186fc4d36fa6a8bf26de64ed9e9f74513f35b1e7aac04f4
6
+ metadata.gz: 635185546a80867d4fc34db6d30153e43533865c3003e64bd7d7fc638cbe0cb97a7770598d3902ccf8fbd53b3b8e15253a0bb2ce4dc36c9e553fe2486491d9f1
7
+ data.tar.gz: 465f1b34aab9ff0c74f690aedcfef27536fea6372df401f5193b90a2347752c58d5e2a7ed020a674ac8f0c468f809b7448cda6f303eb5dd9a48575c7cea43cde
data/CHANGELOG.md CHANGED
@@ -1,3 +1,79 @@
1
+ <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
+
3
+ ## 1.6.2 2021-04-15
4
+
5
+
6
+ ### Added
7
+
8
+ - A default error message for `respond_to?` predicate (@rindek)
9
+
10
+ ### Fixed
11
+
12
+ - Using `respond_to?` predicate in blocks works now (@rindek)
13
+
14
+
15
+ [Compare v1.6.1...v1.6.2](https://github.com/dry-rb/dry-schema/compare/v1.6.1...v1.6.2)
16
+
17
+ ## 1.6.1 2021-02-02
18
+
19
+
20
+ ### Fixed
21
+
22
+ - Messages#[] handles meta/no meta cases more gracefully and has better interoperability with the I18n backend. This brings MessageCompiler#visit_unexpected_key up to parity with MessageCompiler#visit_predicate. Uses visit_predicate as basis for visit_unexpected_key. (@robhanlon22)
23
+
24
+
25
+ [Compare v1.6.0...v1.6.1](https://github.com/dry-rb/dry-schema/compare/v1.6.0...v1.6.1)
26
+
27
+ ## 1.6.0 2021-01-21
28
+
29
+
30
+ ### Fixed
31
+
32
+ - Using sum types with a i18n backend no longer crashes (issue #328 fixes via #331) (@tylerhunt)
33
+
34
+ ### Changed
35
+
36
+ - Inferring predicates from class names is deprecated. It's very unlikely your code depends on it,
37
+ however, if it does, you'll get an exception with instructions. (@flash-gordon)
38
+
39
+ If you see an exception and don't rely on inferring, just disable it with:
40
+
41
+ ```ruby
42
+ Dry::Schema::PredicateInferrer::Compiler.infer_predicate_by_class_name false
43
+ ```
44
+
45
+ Otherwise, enable it explicitly:
46
+
47
+ ```ruby
48
+ Dry::Schema::PredicateInferrer::Compiler.infer_predicate_by_class_name true
49
+ ```
50
+
51
+ See https://github.com/dry-rb/dry-schema/issues/335 for rationale.
52
+
53
+ [Compare v1.5.6...v1.6.0](https://github.com/dry-rb/dry-schema/compare/v1.5.6...v1.6.0)
54
+
55
+ ## 1.5.6 2020-10-21
56
+
57
+
58
+ ### Fixed
59
+
60
+ - Fixed stack error which was a regression introduced in 1.5.5 (issue #322 fixed via #323) (@flash-gordon)
61
+
62
+
63
+ [Compare v1.5.5...v1.5.6](https://github.com/dry-rb/dry-schema/compare/v1.5.5...v1.5.6)
64
+
65
+ ## 1.5.5 2020-10-08
66
+
67
+
68
+ ### Fixed
69
+
70
+ - Key validation works with messages that have meta-data (issue #310 fixed via #313) (@tadeusz-niemiec)
71
+ - Using an external schema along with a key specified as a `:hash` works as expected (issue #296 fixed via #315) (@tadeusz-niemiec + @solnic)
72
+ - `Result#error?(path)` works correctly when the path points to an array item (issue #317 fixed via #318) (@solnic)
73
+
74
+
75
+ [Compare v1.5.4...v1.5.5](https://github.com/dry-rb/dry-schema/compare/v1.5.4...v1.5.5)
76
+
1
77
  ## 1.5.4
2
78
 
3
79
  2020-09-03
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
@@ -21,7 +21,7 @@
21
21
 
22
22
  This library officially supports the following Ruby versions:
23
23
 
24
- * MRI >= `2.4`
24
+ * MRI >= `2.5`
25
25
  * jruby >= `9.2`
26
26
 
27
27
  ## License
data/config/errors.yml CHANGED
@@ -87,6 +87,8 @@ en:
87
87
 
88
88
  type?: "must be %{type}"
89
89
 
90
+ respond_to?: "must respond to %{method}"
91
+
90
92
  size?:
91
93
  arg:
92
94
  default: "size must be %{size}"
data/dry-schema.gemspec CHANGED
@@ -29,16 +29,15 @@ Gem::Specification.new do |spec|
29
29
  spec.metadata['source_code_uri'] = 'https://github.com/dry-rb/dry-schema'
30
30
  spec.metadata['bug_tracker_uri'] = 'https://github.com/dry-rb/dry-schema/issues'
31
31
 
32
- spec.required_ruby_version = ">= 2.4.0"
32
+ spec.required_ruby_version = ">= 2.5.0"
33
33
 
34
34
  # to update dependencies edit project.yml
35
35
  spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
36
36
  spec.add_runtime_dependency "dry-configurable", "~> 0.8", ">= 0.8.3"
37
- spec.add_runtime_dependency "dry-core", "~> 0.4"
38
- spec.add_runtime_dependency "dry-equalizer", "~> 0.2"
37
+ spec.add_runtime_dependency "dry-core", "~> 0.5", ">= 0.5"
39
38
  spec.add_runtime_dependency "dry-initializer", "~> 3.0"
40
39
  spec.add_runtime_dependency "dry-logic", "~> 1.0"
41
- spec.add_runtime_dependency "dry-types", "~> 1.4"
40
+ spec.add_runtime_dependency "dry-types", "~> 1.5"
42
41
 
43
42
  spec.add_development_dependency "bundler"
44
43
  spec.add_development_dependency "rake"
@@ -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/configurable"
5
5
 
6
6
  require "dry/schema/constants"
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "dry/core/cache"
4
- require "dry/equalizer"
4
+ require "dry/core/equalizer"
5
5
 
6
6
  module Dry
7
7
  module Schema
@@ -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/core/cache"
5
5
  require "dry/schema/constants"
6
6
  require "dry/schema/key"
@@ -17,6 +17,7 @@ module Dry
17
17
 
18
18
  undef :eql?
19
19
  undef :nil?
20
+ undef :respond_to?
20
21
 
21
22
  # @!attribute [r] chain
22
23
  # Indicate if the macro should append its rules to the provided trace
@@ -28,10 +28,14 @@ module Dry
28
28
 
29
29
  import_steps(schema)
30
30
 
31
- type(updated_type) unless custom_type? && !current_type.respond_to?(:of)
31
+ if !custom_type? || array_type?(current_type) || hash_type?(current_type)
32
+ type(updated_type)
33
+ elsif maybe_type?(current_type)
34
+ type(updated_type.optional)
35
+ end
32
36
  end
33
37
 
34
- trace_opts = opts.reject { |key, _| key == :type_spec || key == :type_rule }
38
+ trace_opts = opts.reject { |key, _| %i[type_spec type_rule].include?(key) }
35
39
 
36
40
  if (type_rule = opts[:type_rule])
37
41
  trace.append(type_rule).evaluate(*predicates, **trace_opts)
@@ -62,10 +66,16 @@ module Dry
62
66
  primitive_inferrer[type].eql?([::Array])
63
67
  end
64
68
 
69
+ # @api private
65
70
  def hash_type?(type)
66
71
  primitive_inferrer[type].eql?([::Hash])
67
72
  end
68
73
 
74
+ # @api private
75
+ def maybe_type?(type)
76
+ type.meta[:maybe].equal?(true)
77
+ end
78
+
69
79
  # @api private
70
80
  def build_array_type(array_type, member)
71
81
  if array_type.respond_to?(:of)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "dry/initializer"
4
- require "dry/equalizer"
4
+ require "dry/core/equalizer"
5
5
 
6
6
  require "dry/schema/path"
7
7
  require "dry/schema/message/or"
@@ -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/message/or/abstract"
6
6
  require "dry/schema/path"
@@ -38,7 +38,7 @@ module Dry
38
38
  #
39
39
  # @api public
40
40
  def dump
41
- @dump ||= "#{left.dump} #{messages[:or][:text]} #{right.dump}"
41
+ @dump ||= "#{left.dump} #{messages[:or]} #{right.dump}"
42
42
  end
43
43
  alias_method :to_s, :dump
44
44
 
@@ -4,8 +4,9 @@ require "dry/initializer"
4
4
 
5
5
  require "dry/schema/constants"
6
6
  require "dry/schema/message"
7
- require "dry/schema/message_set"
8
7
  require "dry/schema/message_compiler/visitor_opts"
8
+ require "dry/schema/message_set"
9
+ require "dry/schema/path"
9
10
 
10
11
  module Dry
11
12
  module Schema
@@ -109,17 +110,8 @@ module Dry
109
110
  end
110
111
 
111
112
  # @api private
112
- def visit_unexpected_key(node, _opts)
113
- path, input = node
114
-
115
- msg = messages.translate("errors.unexpected_key")
116
-
117
- Message.new(
118
- path: path,
119
- text: msg[:text],
120
- predicate: nil,
121
- input: input
122
- )
113
+ def visit_unexpected_key(node, opts)
114
+ visit_predicate([:unexpected_key, []], opts.dup.update(path: Path[node.first]))
123
115
  end
124
116
 
125
117
  # @api private
@@ -130,7 +122,10 @@ module Dry
130
122
 
131
123
  # @api private
132
124
  def or_translator
133
- @or_translator ||= proc { |k| messages.translate(k, **default_lookup_options) }
125
+ @or_translator ||= proc { |k|
126
+ message = messages.translate(k, **default_lookup_options)
127
+ message.is_a?(Hash) ? message[:text] : message
128
+ }
134
129
  end
135
130
 
136
131
  # @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
  module Dry
6
6
  module Schema
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "set"
4
4
  require "concurrent/map"
5
- require "dry/equalizer"
5
+ require "dry/core/equalizer"
6
6
  require "dry/configurable"
7
7
 
8
8
  require "dry/schema/constants"
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "dry/initializer"
4
- require "dry/equalizer"
4
+ require "dry/core/equalizer"
5
5
 
6
6
  require "dry/schema/constants"
7
7
 
@@ -3,7 +3,7 @@
3
3
  require "yaml"
4
4
  require "pathname"
5
5
 
6
- require "dry/equalizer"
6
+ require "dry/core/equalizer"
7
7
  require "dry/schema/constants"
8
8
  require "dry/schema/messages/abstract"
9
9
 
@@ -90,13 +90,25 @@ module Dry
90
90
  keys.index(key)
91
91
  end
92
92
 
93
+ def without_index
94
+ self.class.new(to_a[0..-2])
95
+ end
96
+
93
97
  # @api private
94
98
  def include?(other)
95
- return false unless same_root?(other)
96
- return last.equal?(other.last) if index? && other.index?
97
- return self.class.new([*to_a[0..-2]]).include?(other) if index?
98
-
99
- self >= other && !other.key_matches(self).include?(nil)
99
+ if !same_root?(other)
100
+ false
101
+ elsif index?
102
+ if other.index?
103
+ last.equal?(other.last)
104
+ else
105
+ without_index.include?(other)
106
+ end
107
+ elsif other.index? && key_matches(other, :select).size < 2
108
+ false
109
+ else
110
+ self >= other && !other.key_matches(self).include?(nil)
111
+ end
100
112
  end
101
113
 
102
114
  # @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
  require "dry/logic/operators"
5
5
 
6
6
  module Dry
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "dry/initializer"
4
- require "dry/equalizer"
4
+ require "dry/core/equalizer"
5
5
 
6
6
  require "dry/schema/path"
7
7
 
@@ -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/initializer"
5
5
 
6
6
  module Dry
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Schema
5
- VERSION = "1.5.4"
5
+ VERSION = "1.6.2"
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.5.4
4
+ version: 1.6.2
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-09-03 00:00:00.000000000 Z
11
+ date: 2021-04-15 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
@@ -106,14 +98,14 @@ dependencies:
106
98
  requirements:
107
99
  - - "~>"
108
100
  - !ruby/object:Gem::Version
109
- version: '1.4'
101
+ version: '1.5'
110
102
  type: :runtime
111
103
  prerelease: false
112
104
  version_requirements: !ruby/object:Gem::Requirement
113
105
  requirements:
114
106
  - - "~>"
115
107
  - !ruby/object:Gem::Version
116
- version: '1.4'
108
+ version: '1.5'
117
109
  - !ruby/object:Gem::Dependency
118
110
  name: bundler
119
111
  requirement: !ruby/object:Gem::Requirement
@@ -253,14 +245,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
253
245
  requirements:
254
246
  - - ">="
255
247
  - !ruby/object:Gem::Version
256
- version: 2.4.0
248
+ version: 2.5.0
257
249
  required_rubygems_version: !ruby/object:Gem::Requirement
258
250
  requirements:
259
251
  - - ">="
260
252
  - !ruby/object:Gem::Version
261
253
  version: '0'
262
254
  requirements: []
263
- rubygems_version: 3.0.3
255
+ rubygems_version: 3.1.6
264
256
  signing_key:
265
257
  specification_version: 4
266
258
  summary: Coercion and validation for data structures