deep_merge_existing_keys 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +3 -0
- data/LICENSE +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/lib/deep_merge_existing_keys.rb +5 -0
- data/lib/deep_merge_existing_keys/core_ext/hash.rb +13 -0
- data/lib/deep_merge_existing_keys/version.rb +3 -0
- data/spec/deep_merge_existing_keys_spec.rb +38 -0
- data/spec/spec_helper.rb +14 -0
- metadata +12 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f01617d880766421fec43a384ca92a103959ad37b926017383506c032cb7427
|
4
|
+
data.tar.gz: 562e32949383d9514bfca8757859854e471037517da414639727b4793b348035
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3e9261b40d2095e3daad77d435d684eaea655c82c1de53622140a62a7f5f60e69ca1c564f293eab827d1e3e441be76953219e93d3896405b447ff26c67986a8
|
7
|
+
data.tar.gz: 61c7fef9b4d1f94907d2c664ab87f7277a448bebe07538c5905a2a2ff31517f68b317ee8286c5b9057a1f4f1911623e6ed41438b469cffcd6b2b3c7a653c7f6b
|
data/.rspec
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Sébastien Gaya
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# DeepMergeExistingKeys
|
2
|
+
|
3
|
+
Extends Rails's deep_merge method to merge only existing keys.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'deep_merge_existing_keys'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install deep_merge_existing_keys
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
old_hash = { a: 10, b: 20, c: { c1: 30, c2: { c2a: 40 } } }
|
25
|
+
new_hash = { b: 25, c: { c1: 35, c2: { c2b: 55 } }, d: 65 }
|
26
|
+
|
27
|
+
merged_hash = old_hash.deep_merge_existing_keys new_hash
|
28
|
+
merged_hash # { a: 10, b: 25, c: { c1: 35, c2: { c2a: 40 } }
|
29
|
+
```
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/lespoupeesrusses/deep_merge_existing_keys. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
38
|
+
|
39
|
+
## Code of Conduct
|
40
|
+
|
41
|
+
Everyone interacting in the DeepMergeExistingKeys project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/lespoupeesrusses/deep_merge_existing_keys/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
class Hash
|
2
|
+
def deep_merge_existing_keys(other_hash)
|
3
|
+
dup.deep_merge_existing_keys!(other_hash)
|
4
|
+
end
|
5
|
+
|
6
|
+
def deep_merge_existing_keys!(other_hash)
|
7
|
+
other_hash.each_pair do |k,v|
|
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
|
10
|
+
end
|
11
|
+
self
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
RSpec.describe DeepMergeExistingKeys do
|
2
|
+
it "has a version number" do
|
3
|
+
expect(DeepMergeExistingKeys::VERSION).not_to be nil
|
4
|
+
end
|
5
|
+
|
6
|
+
it "does its job" do
|
7
|
+
old_hash = {
|
8
|
+
a: 10,
|
9
|
+
b: 20,
|
10
|
+
c: {
|
11
|
+
c1: 30,
|
12
|
+
c2: { c2a: 40 }
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
new_hash = {
|
17
|
+
b: 25,
|
18
|
+
c: {
|
19
|
+
c1: 35,
|
20
|
+
c2: { c2b: 55 }
|
21
|
+
},
|
22
|
+
d: 65
|
23
|
+
}
|
24
|
+
|
25
|
+
result_hash = {
|
26
|
+
a: 10,
|
27
|
+
b: 25,
|
28
|
+
c: {
|
29
|
+
c1: 35,
|
30
|
+
c2: {
|
31
|
+
c2a: 40
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
expect(old_hash.deep_merge_existing_keys(new_hash)).to eq(result_hash)
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "deep_merge_existing_keys"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# Enable flags like --only-failures and --next-failure
|
6
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
7
|
+
|
8
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
9
|
+
config.disable_monkey_patching!
|
10
|
+
|
11
|
+
config.expect_with :rspec do |c|
|
12
|
+
c.syntax = :expect
|
13
|
+
end
|
14
|
+
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.0.1
|
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-
|
11
|
+
date: 2019-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -72,7 +72,16 @@ email:
|
|
72
72
|
executables: []
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
|
-
files:
|
75
|
+
files:
|
76
|
+
- ".rspec"
|
77
|
+
- LICENSE
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- lib/deep_merge_existing_keys.rb
|
81
|
+
- lib/deep_merge_existing_keys/core_ext/hash.rb
|
82
|
+
- lib/deep_merge_existing_keys/version.rb
|
83
|
+
- spec/deep_merge_existing_keys_spec.rb
|
84
|
+
- spec/spec_helper.rb
|
76
85
|
homepage: https://github.com/lespoupeesrusses/deep_merge_existing_keys
|
77
86
|
licenses:
|
78
87
|
- MIT
|