dry-schema 1.3.0 → 1.3.1

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: c2703b501037f07e55a7018b8e0e048525e591d2f5cb5e369717a0635aacd443
4
- data.tar.gz: e199bafff541bee970435b2dd26ce10b888c2167d5aec919dafbf91b089311ea
3
+ metadata.gz: 7a41a84d107f4694b4009a58065e603b2489e87b55c91fba3884b2af2562d3ef
4
+ data.tar.gz: fce0be0f38499c070f1fd1dc55c3c3407decef76aba778b3a27a839440bd888f
5
5
  SHA512:
6
- metadata.gz: b7512d9308582c306717a507ad4c218e50137e13699dacadcdb4d9f5d8bb01cfae635cdd78a27d4466e620c13e43d63b4cc7f27112d1bbaf74bdc5e7c7e1d384
7
- data.tar.gz: 58bc3d577e79752c8495749af8dc9304d1bcae753f6a612fbf744f4dc9586a65aafceb038c9ec6198361edd0b7f930e8f59abd600c74b3ba562de32a5d967e70
6
+ metadata.gz: 3fb5a9045111eadb411f2afc39819dba78651a9170968b212eaebfd613376f7a22db40660e90b3ac6d264177a1e8d1ead05736f8ed2b13a5d3bdaf1e382f2c44
7
+ data.tar.gz: c995cfb2e5e4c5f90d6109cbd01a81e627027ac730034422a3d1fbb791ab248bc9572d59fef5ff7c54cb69baeaeb6d8e21914e5641ba81f560e3cff4fc31673d
@@ -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
@@ -60,7 +60,7 @@ module Dry
60
60
  #
61
61
  # If a string is passed, it will be compared with the text
62
62
  #
63
- # @param [Message,String]
63
+ # @param other [Message,String]
64
64
  #
65
65
  # @return [Boolean]
66
66
  #
@@ -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 false if index? && other.index? && !last.equal?(other.last)
69
- self >= other
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Schema
5
- VERSION = '1.3.0'
5
+ VERSION = '1.3.1'
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.3.0
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-06 00:00:00.000000000 Z
11
+ date: 2019-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby