elasticgraph-support 0.18.0.0 → 0.18.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/elastic_graph/support/hash_util.rb +37 -0
- data/lib/elastic_graph/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: c162ea60bd30d78868194b99b17ba02e7e65f733eee3d9a190a552e235a4dde5
|
4
|
+
data.tar.gz: f9d16bc85090dd8a3a95cd332baaf50dfa6f88a8d0b57248e58d41667fd3d31a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac4228dad6cc3516e3e76c3a1cc25392dd47c0697e97a8bca82178eddc67d4b643dbabd85a8ab8bfc71de6b40e24eaea1b7f602cc3431a3fcc71e1e5f2cb6412
|
7
|
+
data.tar.gz: e213357b0f4829c77296d7e46fdf8aaf1e18272cde2e98b06f1eb82308de7e9f3f39ba2298d94c53d15d64fe615eb87ca165071db62bce57ee92a941c7d3bb75
|
@@ -9,6 +9,43 @@
|
|
9
9
|
module ElasticGraph
|
10
10
|
module Support
|
11
11
|
class HashUtil
|
12
|
+
# Fetches a key from a hash (just like `Hash#fetch`) but with a more verbose error message when the key is not found.
|
13
|
+
# The error message indicates the available keys unlike `Hash#fetch`.
|
14
|
+
def self.verbose_fetch(hash, key)
|
15
|
+
hash.fetch(key) do
|
16
|
+
raise ::KeyError, "key not found: #{key.inspect}. Available keys: #{hash.keys.inspect}."
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Like `Hash#to_h`, but strict. When the given input has conflicting keys, `Hash#to_h` will happily let
|
21
|
+
# the last pair when. This method instead raises an exception.
|
22
|
+
def self.strict_to_h(pairs)
|
23
|
+
hash = pairs.to_h
|
24
|
+
|
25
|
+
if hash.size < pairs.size
|
26
|
+
conflicting_keys = pairs.map(&:first).tally.filter_map { |key, count| key if count > 1 }
|
27
|
+
raise ::KeyError, "Cannot build a strict hash, since input has conflicting keys: #{conflicting_keys.inspect}."
|
28
|
+
end
|
29
|
+
|
30
|
+
hash
|
31
|
+
end
|
32
|
+
|
33
|
+
# Like `Hash#merge`, but verifies that the hashes were strictly disjoint (e.g. had no keys in common).
|
34
|
+
# An error is raised if they do have any keys in common.
|
35
|
+
def self.disjoint_merge(hash1, hash2)
|
36
|
+
conflicting_keys = [] # : ::Array[untyped]
|
37
|
+
merged = hash1.merge(hash2) do |key, v1, _v2|
|
38
|
+
conflicting_keys << key
|
39
|
+
v1
|
40
|
+
end
|
41
|
+
|
42
|
+
unless conflicting_keys.empty?
|
43
|
+
raise ::KeyError, "Hashes were not disjoint. Conflicting keys: #{conflicting_keys.inspect}."
|
44
|
+
end
|
45
|
+
|
46
|
+
merged
|
47
|
+
end
|
48
|
+
|
12
49
|
# Recursively transforms any hash keys in the given object to string keys, without
|
13
50
|
# mutating the provided argument.
|
14
51
|
def self.stringify_keys(object)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticgraph-support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.18.0.
|
4
|
+
version: 0.18.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Myron Marston
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop-factory_bot
|