elasticgraph-support 0.18.0.0 → 0.18.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a6c3aca3ffb3ca4835a6e051afe7dee323348ef1d819a30dca05b1f6d06d452
4
- data.tar.gz: a52ecb10ebd1065e9780aa3dabf71848200e96409b110122f00bd5569e485fa7
3
+ metadata.gz: c162ea60bd30d78868194b99b17ba02e7e65f733eee3d9a190a552e235a4dde5
4
+ data.tar.gz: f9d16bc85090dd8a3a95cd332baaf50dfa6f88a8d0b57248e58d41667fd3d31a
5
5
  SHA512:
6
- metadata.gz: 6ab3fb42baad12fcab9414a262f0b2ddfddb20d90cbd0913f65fb0a1dfecbb1e5c9b17231ea337d0a1a3ea20854ce310b8ecf905fb528a975e14406f6e46905d
7
- data.tar.gz: 391e5007037fbdfd29134d2dd6cbaa5313fa8b031b2a4366c58d8c036940ef318d1571d16aee18aeab520eca2c8275f1d79b5842b07943cebed143797d069ac5
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)
@@ -8,7 +8,7 @@
8
8
 
9
9
  module ElasticGraph
10
10
  # The version of all ElasticGraph gems.
11
- VERSION = "0.18.0.0"
11
+ VERSION = "0.18.0.1"
12
12
 
13
13
  # Steep weirdly expects this here...
14
14
  # @dynamic self.define_schema
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.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-27 00:00:00.000000000 Z
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