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 +4 -4
- data/lib/utils/hash_transform_keys.rb +16 -0
- data/lib/utils/version.rb +1 -1
- data/spec/hash_transform_keys_spec.rb +7 -0
- 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: cb766833ae078338bdac8e0954736f83dfc5feee9de6cbc15c03bd1998848529
|
4
|
+
data.tar.gz: 93ee70fa9e268f252c5c9c3f5dd58e2859c2b794b13d50e117f374ae8e80efde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
@@ -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.
|
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-
|
11
|
+
date: 2022-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|