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: 5f01617d880766421fec43a384ca92a103959ad37b926017383506c032cb7427
4
- data.tar.gz: 562e32949383d9514bfca8757859854e471037517da414639727b4793b348035
3
+ metadata.gz: b37271eff42c6b97d97562b1e0f39a8e6dd241c42a16ff385044ac04e54d192c
4
+ data.tar.gz: eec2f712f18f32235127f55b7115db86c7fd4a4523b5dccd465ef67ca0e72aa2
5
5
  SHA512:
6
- metadata.gz: b3e9261b40d2095e3daad77d435d684eaea655c82c1de53622140a62a7f5f60e69ca1c564f293eab827d1e3e441be76953219e93d3896405b447ff26c67986a8
7
- data.tar.gz: 61c7fef9b4d1f94907d2c664ab87f7277a448bebe07538c5905a2a2ff31517f68b317ee8286c5b9057a1f4f1911623e6ed41438b469cffcd6b2b3c7a653c7f6b
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
- self[k] = self[k].is_a?(Hash) && v.is_a?(Hash) ? self[k].deep_merge_existing_keys(v) : v
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
@@ -1,3 +1,3 @@
1
1
  module DeepMergeExistingKeys
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -3,7 +3,7 @@ RSpec.describe DeepMergeExistingKeys do
3
3
  expect(DeepMergeExistingKeys::VERSION).not_to be nil
4
4
  end
5
5
 
6
- it "does its job" do
6
+ it "does its basic job" do
7
7
  old_hash = {
8
8
  a: 10,
9
9
  b: 20,
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.1
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: 2019-05-13 00:00:00.000000000 Z
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: '10.0'
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: '10.0'
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.0.1
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.