deep_merge_existing_keys 1.0.1 → 1.1.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b37271eff42c6b97d97562b1e0f39a8e6dd241c42a16ff385044ac04e54d192c
|
4
|
+
data.tar.gz: eec2f712f18f32235127f55b7115db86c7fd4a4523b5dccd465ef67ca0e72aa2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de02c50e0f7181be313df171e7914c23305ba3504d3f9f530a0fa25e97f622457608cc0d0127dcce6a1a89a46873f2eb2094b4d3d88ec38a44fe298e429a32b7
|
7
|
+
data.tar.gz: 954dc268278f429a976ee7db9d70f31e74add70ed2b7165986d8016bacdf23a8b4adecbdfc81d2926de931f420af751f1c36f9d7b58fe6fe985fed7c4f1ef3e0
|
@@ -1,12 +1,19 @@
|
|
1
1
|
class Hash
|
2
|
-
def deep_merge_existing_keys(other_hash)
|
3
|
-
dup.deep_merge_existing_keys!(other_hash)
|
2
|
+
def deep_merge_existing_keys(other_hash, &block)
|
3
|
+
dup.deep_merge_existing_keys!(other_hash, &block)
|
4
4
|
end
|
5
5
|
|
6
|
-
def deep_merge_existing_keys!(other_hash)
|
6
|
+
def deep_merge_existing_keys!(other_hash, &block)
|
7
7
|
other_hash.each_pair do |k,v|
|
8
8
|
next unless self.keys.include? k
|
9
|
-
|
9
|
+
|
10
|
+
self[k] = if self[k].is_a?(Hash) && v.is_a?(Hash)
|
11
|
+
self[k].deep_merge_existing_keys(v, &block)
|
12
|
+
elsif block_given?
|
13
|
+
block.call(k, self[k], v)
|
14
|
+
else
|
15
|
+
v
|
16
|
+
end
|
10
17
|
end
|
11
18
|
self
|
12
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deep_merge_existing_keys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sébastien Gaya
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
103
|
requirements: []
|
104
|
-
rubygems_version: 3.
|
104
|
+
rubygems_version: 3.1.2
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
107
|
summary: Extends Rails's deep_merge method to merge only existing keys.
|