dry-schema 1.3.0 → 1.3.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 +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/dry/schema/extensions/hints/message_set_methods.rb +48 -1
- data/lib/dry/schema/message.rb +1 -1
- data/lib/dry/schema/path.rb +10 -6
- data/lib/dry/schema/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a41a84d107f4694b4009a58065e603b2489e87b55c91fba3884b2af2562d3ef
|
4
|
+
data.tar.gz: fce0be0f38499c070f1fd1dc55c3c3407decef76aba778b3a27a839440bd888f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fb5a9045111eadb411f2afc39819dba78651a9170968b212eaebfd613376f7a22db40660e90b3ac6d264177a1e8d1ead05736f8ed2b13a5d3bdaf1e382f2c44
|
7
|
+
data.tar.gz: c995cfb2e5e4c5f90d6109cbd01a81e627027ac730034422a3d1fbb791ab248bc9572d59fef5ff7c54cb69baeaeb6d8e21914e5641ba81f560e3cff4fc31673d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
# 1.3.1 2019-07-08
|
2
|
+
|
3
|
+
### Fixed
|
4
|
+
|
5
|
+
* `Result#error?` works correctly with nested hashes and arrays (@solnic)
|
6
|
+
* `:hints` extension no longer causes a crash where base messages are generated too (issue #165) (@solnic)
|
7
|
+
|
8
|
+
[Compare v1.3.0...v1.3.1](https://github.com/dry-rb/dry-schema/compare/v1.3.0...v1.3.1)
|
9
|
+
|
1
10
|
# 1.3.0 2019-07-06
|
2
11
|
|
3
12
|
### Added
|
@@ -12,7 +12,7 @@ module Dry
|
|
12
12
|
#
|
13
13
|
# @return [Array<Message::Hint>]
|
14
14
|
attr_reader :hints
|
15
|
-
|
15
|
+
|
16
16
|
# Configuration option to enable/disable showing errors
|
17
17
|
#
|
18
18
|
# @return [Boolean]
|
@@ -37,6 +37,53 @@ module Dry
|
|
37
37
|
@to_h ||= failures ? messages_map : messages_map(hints)
|
38
38
|
end
|
39
39
|
alias_method :to_hash, :to_h
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
# @api private
|
44
|
+
def unique_paths
|
45
|
+
messages.uniq(&:path).map(&:path)
|
46
|
+
end
|
47
|
+
|
48
|
+
# @api private
|
49
|
+
def messages_map(messages = self.messages)
|
50
|
+
return EMPTY_HASH if empty?
|
51
|
+
|
52
|
+
messages.reduce(placeholders) { |hash, msg|
|
53
|
+
node = msg.path.reduce(hash) { |a, e| a.is_a?(Hash) ? a[e] : a.last[e] }
|
54
|
+
(node[0].is_a?(::Array) ? node[0] : node) << msg.dump
|
55
|
+
hash
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
# @api private
|
60
|
+
#
|
61
|
+
# rubocop:disable Metrics/AbcSize
|
62
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
63
|
+
def initialize_placeholders!
|
64
|
+
@placeholders = unique_paths.each_with_object(EMPTY_HASH.dup) { |path, hash|
|
65
|
+
curr_idx = 0
|
66
|
+
last_idx = path.size - 1
|
67
|
+
node = hash
|
68
|
+
|
69
|
+
while curr_idx <= last_idx
|
70
|
+
key = path[curr_idx]
|
71
|
+
|
72
|
+
next_node =
|
73
|
+
if node.is_a?(Array) && key.is_a?(Symbol)
|
74
|
+
node_hash = (node << [] << {}).last
|
75
|
+
node_hash[key] || (node_hash[key] = curr_idx < last_idx ? {} : [])
|
76
|
+
else
|
77
|
+
node[key] || (node[key] = curr_idx < last_idx ? {} : [])
|
78
|
+
end
|
79
|
+
|
80
|
+
node = next_node
|
81
|
+
curr_idx += 1
|
82
|
+
end
|
83
|
+
}
|
84
|
+
end
|
85
|
+
# rubocop:enable Metrics/AbcSize
|
86
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
40
87
|
end
|
41
88
|
end
|
42
89
|
end
|
data/lib/dry/schema/message.rb
CHANGED
data/lib/dry/schema/path.rb
CHANGED
@@ -65,8 +65,10 @@ module Dry
|
|
65
65
|
# @api private
|
66
66
|
def include?(other)
|
67
67
|
return false unless same_root?(other)
|
68
|
-
return
|
69
|
-
self
|
68
|
+
return last.equal?(other.last) if index? && other.index?
|
69
|
+
return self.class.new([*to_a[0..-2]]).include?(other) if index?
|
70
|
+
|
71
|
+
self >= other && !other.key_matches(self).include?(nil)
|
70
72
|
end
|
71
73
|
|
72
74
|
# @api private
|
@@ -75,14 +77,16 @@ module Dry
|
|
75
77
|
|
76
78
|
return 0 if keys.eql?(other.keys)
|
77
79
|
|
78
|
-
res =
|
79
|
-
map { |key| (idx = other.index(key)) && keys[idx].equal?(key) }
|
80
|
-
.compact
|
81
|
-
.reject { |value| value.equal?(false) }
|
80
|
+
res = key_matches(other).compact.reject { |value| value.equal?(false) }
|
82
81
|
|
83
82
|
res.size < count ? 1 : -1
|
84
83
|
end
|
85
84
|
|
85
|
+
# @api private
|
86
|
+
def key_matches(other)
|
87
|
+
map { |key| (idx = other.index(key)) && keys[idx].equal?(key) }
|
88
|
+
end
|
89
|
+
|
86
90
|
# @api private
|
87
91
|
def last
|
88
92
|
keys.last
|
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.3.
|
4
|
+
version: 1.3.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: 2019-07-
|
11
|
+
date: 2019-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|