metanorma-utils 1.3.1 → 1.3.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: fd89605d15a5973a46c4fbc9b88c024191e6a809e4255f34db32d57bab198cc3
4
- data.tar.gz: 167f7c09e8b6347c0f5990656775cba5ec5cdc05a2b715690451e3c02f80fb65
3
+ metadata.gz: cb766833ae078338bdac8e0954736f83dfc5feee9de6cbc15c03bd1998848529
4
+ data.tar.gz: 93ee70fa9e268f252c5c9c3f5dd58e2859c2b794b13d50e117f374ae8e80efde
5
5
  SHA512:
6
- metadata.gz: 1baca64c93f1598bd4f6285ac62c912a519a36c9a9ee08dfe883fe5af0cd721983cc3be513d2dd3d8329ff9efbcc940f0f207ed40791e93556a477ac230c6bb0
7
- data.tar.gz: f4a13c5846b93d6fa7262736a5e177e809ddf72340713c890a7bcddad8d2ba2526e71ee5eff0dd3900e10a6c45b0f00cf7944a30ab1343feef34d3679428e795
6
+ metadata.gz: 8572ae07eb6b970d0b00c1289b0652c293690b241b4d39a91b4df235a77ef29809dba122be75795bd7f8bde1fcebd59deeee9cb4f001259675626f73e0cd5869
7
+ data.tar.gz: 63f761a6ada0d87f7663811b89f594eb23dafb9d9da9c130d158bd58671648fc5b6cd8a3ed9db895345b1267e3c02141937bda7141e414971dabafa9ec93bbaa
@@ -48,4 +48,20 @@ class Hash
48
48
  end
49
49
  result
50
50
  end
51
+
52
+ def deep_merge(second)
53
+ merger = proc { |_, v1, v2|
54
+ if Hash === v1 && Hash === v2
55
+ v1.merge(v2, &merger)
56
+ elsif Array === v1 && Array === v2
57
+ v1 | v2
58
+ elsif [:undefined, nil,
59
+ :nil].include?(v2)
60
+ v1
61
+ else
62
+ v2
63
+ end
64
+ }
65
+ merge(second.to_h, &merger)
66
+ end
51
67
  end
data/lib/utils/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Utils
3
- VERSION = "1.3.1".freeze
3
+ VERSION = "1.3.2".freeze
4
4
  end
5
5
  end
@@ -49,4 +49,11 @@ RSpec.describe Metanorma::Utils do
49
49
  expect(result[:test4][0]).to include(:test41)
50
50
  expect(result[:test4][0][:test41]).to eq("test41")
51
51
  end
52
+
53
+ it "deep merges hashes" do
54
+ hash1 = { a: [1, 2], b: "c", c: 4, e: { f: { g: "1" } } }
55
+ hash2 = { a: [3], b: "d", d: 5, e: { f: { h: "2" } } }
56
+ expect(hash1.deep_merge(hash2)).to eq({ a: [1, 2, 3], b: "d", c: 4,
57
+ d: 5, e: { f: { g: "1", h: "2" } } })
58
+ end
52
59
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-20 00:00:00.000000000 Z
11
+ date: 2022-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor