deep_merge 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG +7 -0
- data/README.md +27 -6
- data/lib/deep_merge/core.rb +5 -0
- data/test/test_deep_merge.rb +6 -0
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5e190853b33fb89d42881c6615a17c4fc50757ab261bae87e2639d553cf07dbe
|
4
|
+
data.tar.gz: 3c2d1e368cbc141220ab2a1c2ec7a346d085f7d6f3306f34da16027f08ef6825
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c71ee77b10d24d27d0814d5d23441855b6e1fc226a842f734919622e707aaffa0063e7cdaec7b1591bf5d6a0a1910260b727462074f655cb3a486419d9086165
|
7
|
+
data.tar.gz: 7ed27c1eaa73425856fedc0379c0ecec51d6636ea5abe5f9cf2c48e7d7f36f7ffafc579eca8b3d1b42486a6e2f27ceb2cd99bdfbb27df3d7596f13ad7543482e
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
2022-01-07 Jason Frey <fryguy9@gmail.com>
|
2
|
+
* Ship version 1.2.2
|
3
|
+
|
4
|
+
* Switched to GitHub actions and add testing of Rubies up to Ruby 3.0
|
5
|
+
* Fixed issue with keep_duplicate_arrays when merging into a nil array. Thanks ALTinners!
|
6
|
+
* Added documentation for keep_duplicate_arrays
|
7
|
+
|
1
8
|
2017-11-16 Jason Frey <fryguy9@gmail.com>
|
2
9
|
* Ship version 1.2.1
|
3
10
|
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
-
DeepMerge
|
2
|
-
|
1
|
+
DeepMerge
|
2
|
+
=========
|
3
|
+
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/deep_merge.svg)](http://badge.fury.io/rb/deep_merge)
|
5
|
+
[![CI](https://github.com/danielsdeleo/deep_merge/actions/workflows/ci.yaml/badge.svg)](https://github.com/danielsdeleo/deep_merge/actions/workflows/ci.yaml)
|
3
6
|
|
4
7
|
Deep Merge is a simple set of utility functions for Hash. It permits you to merge elements inside a hash together recursively. The manner by which it does this is somewhat arbitrary (since there is no defining standard for this) but it should end up being pretty intuitive and do what you expect.
|
5
8
|
|
@@ -39,6 +42,8 @@ Options are specified in the last parameter passed, which should be in hash form
|
|
39
42
|
Set to true to merge hashes within arrays
|
40
43
|
:extend_existing_arrays DEFAULT: false
|
41
44
|
Set to true to extend existing arrays, instead of overwriting them
|
45
|
+
:keep_array_duplicates DEFAULT: false
|
46
|
+
Set to true to keep duplicate entries in arrays, instead of coalescing them
|
42
47
|
:merge_nil_values DEFAULT: false
|
43
48
|
Set to true to merge nil hash values, overwriting a possibly non-nil value
|
44
49
|
:merge_debug DEFAULT: false
|
@@ -64,7 +69,6 @@ Additionally, if the knockout_prefix is passed alone as a string, it will cause
|
|
64
69
|
Results: {:x => ""}
|
65
70
|
|
66
71
|
**:overwrite_arrays**
|
67
|
-
|
68
72
|
The purpose of this is to provide a way to replace Arrays instead of having them merge together.
|
69
73
|
|
70
74
|
source = {:x => ['1', '2']}
|
@@ -73,7 +77,6 @@ The purpose of this is to provide a way to replace Arrays instead of having them
|
|
73
77
|
Results: {:x => ['1', '2']}
|
74
78
|
|
75
79
|
**:unpack_arrays**
|
76
|
-
|
77
80
|
The purpose of this is to permit compound elements to be passed in as strings and to be converted into discrete array elements
|
78
81
|
|
79
82
|
irsource = {:x => ['1,2,3', '4']}
|
@@ -101,6 +104,24 @@ Push src elements to existing arrays, instead of overwriting them.
|
|
101
104
|
dest.deep_merge!(source, {:extend_existing_arrays => true})
|
102
105
|
Results: {"property" => ["1", "2", "3", "4"]}
|
103
106
|
|
107
|
+
**:keep_array_duplicates**
|
108
|
+
|
109
|
+
Keeps duplicate entries in arrays, instead of coalescing them.
|
110
|
+
|
111
|
+
Without this setting:
|
112
|
+
|
113
|
+
source = { "property" => ["2", "3"] }
|
114
|
+
dest = { "property" => ["1", "2"] }
|
115
|
+
dest.deep_merge!(source)
|
116
|
+
Results: {"property" => ["1", "2", "3"]}
|
117
|
+
|
118
|
+
With this setting:
|
119
|
+
|
120
|
+
source = { "property" => ["1", "2"] }
|
121
|
+
dest = { "property" => ["2", "3"] }
|
122
|
+
dest.deep_merge!(source, {:keep_array_duplicates => true})
|
123
|
+
Results: {"property" => ["1", "2", "2", "3"]}
|
124
|
+
|
104
125
|
**:merge_nil_values**
|
105
126
|
|
106
127
|
The purpose of this option is to allow nil hash values to be merged. The prior behavior was to discard nil hash values and remains the default if not specified.
|
@@ -138,8 +159,8 @@ Simple Example Code
|
|
138
159
|
y.deep_merge!(x)
|
139
160
|
# results: y = {:x => [1,2,3,4,5]}
|
140
161
|
|
141
|
-
|
142
|
-
|
162
|
+
Availability
|
163
|
+
============
|
143
164
|
|
144
165
|
`deep_merge` was written by Steve Midgley, and is now maintained by Daniel DeLeo. The official home of `deep_merge` on the internet is now https://github.com/danielsdeleo/deep_merge
|
145
166
|
|
data/lib/deep_merge/core.rb
CHANGED
@@ -122,6 +122,11 @@ module DeepMerge
|
|
122
122
|
rescue TypeError
|
123
123
|
src_dup = src_value
|
124
124
|
end
|
125
|
+
if src_dup.kind_of?(Array) && keep_array_duplicates
|
126
|
+
# note: in this case the merge will be additive, rather than a bounded set, so we can't simply merge src with itself
|
127
|
+
# We need to merge src with an empty array
|
128
|
+
src_dup = []
|
129
|
+
end
|
125
130
|
dest[src_key] = deep_merge!(src_value, src_dup, options.merge(:debug_indent => di + ' '))
|
126
131
|
end
|
127
132
|
elsif dest.kind_of?(Array) && extend_existing_arrays
|
data/test/test_deep_merge.rb
CHANGED
@@ -630,6 +630,12 @@ class TestDeepMerge < Test::Unit::TestCase
|
|
630
630
|
DeepMerge::deep_merge!(hash_src, hash_dst, {:keep_array_duplicates => true})
|
631
631
|
assert_equal({"item" => ["1", "2", "2", "3"]}, hash_dst)
|
632
632
|
|
633
|
+
# For Issue 34 - keep_array_duplicates against a nil src doesn't do a recursive merge
|
634
|
+
hash_src = {"item" => ["2", "3"]}
|
635
|
+
hash_dst = { }
|
636
|
+
DeepMerge::deep_merge!(hash_src, hash_dst, {:keep_array_duplicates => true})
|
637
|
+
assert_equal({"item" => ["2", "3"]}, hash_dst)
|
638
|
+
|
633
639
|
# Don't merge nil values by default
|
634
640
|
hash_src = {"item" => nil}
|
635
641
|
hash_dst = {"item" => "existing"}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deep_merge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Midgley
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -59,7 +59,7 @@ homepage: https://github.com/danielsdeleo/deep_merge
|
|
59
59
|
licenses:
|
60
60
|
- MIT
|
61
61
|
metadata: {}
|
62
|
-
post_install_message:
|
62
|
+
post_install_message:
|
63
63
|
rdoc_options: []
|
64
64
|
require_paths:
|
65
65
|
- lib
|
@@ -74,9 +74,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
requirements: []
|
77
|
-
|
78
|
-
|
79
|
-
signing_key:
|
77
|
+
rubygems_version: 3.1.6
|
78
|
+
signing_key:
|
80
79
|
specification_version: 4
|
81
80
|
summary: Merge Deeply Nested Hashes
|
82
81
|
test_files:
|