New Upstream Release - ruby-deep-merge

Ready changes

Summary

Merged new upstream version: 1.2.2 (was: 1.1.1).

Resulting package

Built on 2022-05-06T23:04 (took 2m36s)

The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:

apt install -t fresh-releases ruby-deep-merge

Lintian Result

Diff

diff --git a/CHANGELOG b/CHANGELOG
index cd1c14f..35a3406 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,21 @@
+2022-01-07 Jason Frey <fryguy9@gmail.com>
+  * Ship version 1.2.2
+
+  * Switched to GitHub actions and add testing of Rubies up to Ruby 3.0
+  * Fixed issue with keep_duplicate_arrays when merging into a nil array. Thanks ALTinners!
+  * Added documentation for keep_duplicate_arrays
+
+2017-11-16 Jason Frey <fryguy9@gmail.com>
+  * Ship version 1.2.1
+
+  * Fixed release date in the gemspec.
+
+2017-11-16 Jason Frey <fryguy9@gmail.com>
+  * Ship version 1.2.0
+
+2017-04-25 Joe Rafaniello <jrafanie@redhat.com>
+  * Merge nil values or keep the original via an option
+
 2016-08-01 Jason Frey <fryguy9@gmail.com>
   * Ship version 1.1.1
 
diff --git a/README.md b/README.md
index 6f0991c..3877893 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,8 @@
-DeepMerge Overview
-==================
+DeepMerge
+=========
+
+[![Gem Version](https://badge.fury.io/rb/deep_merge.svg)](http://badge.fury.io/rb/deep_merge)
+[![CI](https://github.com/danielsdeleo/deep_merge/actions/workflows/ci.yaml/badge.svg)](https://github.com/danielsdeleo/deep_merge/actions/workflows/ci.yaml)
 
 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.
 
@@ -39,6 +42,10 @@ Options are specified in the last parameter passed, which should be in hash form
       Set to true to merge hashes within arrays
     :extend_existing_arrays DEFAULT: false
       Set to true to extend existing arrays, instead of overwriting them
+    :keep_array_duplicates  DEFAULT: false
+      Set to true to keep duplicate entries in arrays, instead of coalescing them
+    :merge_nil_values       DEFAULT: false
+      Set to true to merge nil hash values, overwriting a possibly non-nil value
     :merge_debug            DEFAULT: false
       Set to true to get console output of merge process for debugging
 
@@ -62,7 +69,6 @@ Additionally, if the knockout_prefix is passed alone as a string, it will cause
     Results: {:x => ""}
 
 **:overwrite_arrays**
-
 The purpose of this is to provide a way to replace Arrays instead of having them merge together.
 
     source = {:x => ['1', '2']}
@@ -71,7 +77,6 @@ The purpose of this is to provide a way to replace Arrays instead of having them
     Results: {:x => ['1', '2']}
 
 **:unpack_arrays**
-
 The purpose of this is to permit compound elements to be passed in as strings and to be converted into discrete array elements
 
     irsource = {:x => ['1,2,3', '4']}
@@ -99,6 +104,33 @@ Push src elements to existing arrays, instead of overwriting them.
     dest.deep_merge!(source, {:extend_existing_arrays => true})
     Results: {"property" => ["1", "2", "3", "4"]}
 
+**:keep_array_duplicates**
+
+Keeps duplicate entries in arrays, instead of coalescing them.
+
+Without this setting:
+
+    source = { "property" => ["2", "3"] }
+    dest   = { "property" => ["1", "2"] }
+    dest.deep_merge!(source)
+    Results: {"property" => ["1", "2", "3"]}
+
+With this setting:
+
+    source = { "property" => ["1", "2"] }
+    dest   = { "property" => ["2", "3"] }
+    dest.deep_merge!(source, {:keep_array_duplicates => true})
+    Results: {"property" => ["1", "2", "2", "3"]}
+
+**:merge_nil_values**
+
+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.
+
+    source = {"item" => nil}
+    dest   = {"item" => "existing"}
+    dest.deep_merge!(source, {:merge_nil_values => true})
+    Results: {"item" => nil}
+
 There are many tests for this library - and you can learn more about the features and usages of deep_merge! by just browsing the test examples.
 
 Using deep_merge in Rails
@@ -127,8 +159,8 @@ Simple Example Code
     y.deep_merge!(x)
     # results: y = {:x => [1,2,3,4,5]}
 
-Availablility
-=============
+Availability
+============
 
 `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
 
diff --git a/debian/changelog b/debian/changelog
index d72ee01..97bc39a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+ruby-deep-merge (1.2.2-1) UNRELEASED; urgency=low
+
+  * New upstream release.
+
+ -- Debian Janitor <janitor@jelmer.uk>  Fri, 06 May 2022 23:01:44 -0000
+
 ruby-deep-merge (1.1.1-2) unstable; urgency=medium
 
   * Team upload
diff --git a/deep_merge.gemspec b/deep_merge.gemspec
index 1aa3b09..c2e69f9 100644
--- a/deep_merge.gemspec
+++ b/deep_merge.gemspec
@@ -2,37 +2,35 @@
 # This file has been automatically generated by gem2tgz #
 #########################################################
 # -*- encoding: utf-8 -*-
+# stub: deep_merge 1.2.2 ruby lib
 
 Gem::Specification.new do |s|
-  s.name = "deep_merge"
-  s.version = "1.1.1"
+  s.name = "deep_merge".freeze
+  s.version = "1.2.2"
 
-  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
-  s.authors = ["Steve Midgley"]
-  s.date = "2016-08-01"
-  s.description = "Recursively merge hashes."
-  s.email = "dan@kallistec.com"
-  s.extra_rdoc_files = ["LICENSE", "README.md"]
-  s.files = ["CHANGELOG", "LICENSE", "README.md", "Rakefile", "lib/deep_merge.rb", "lib/deep_merge/core.rb", "lib/deep_merge/deep_merge_hash.rb", "lib/deep_merge/rails_compat.rb", "test/test_deep_merge.rb"]
-  s.homepage = "https://github.com/danielsdeleo/deep_merge"
-  s.licenses = ["MIT"]
-  s.require_paths = ["lib"]
-  s.rubygems_version = "1.8.23"
-  s.summary = "Merge Deeply Nested Hashes"
-  s.test_files = ["test/test_deep_merge.rb"]
+  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
+  s.require_paths = ["lib".freeze]
+  s.authors = ["Steve Midgley".freeze]
+  s.date = "2022-01-07"
+  s.description = "Recursively merge hashes.".freeze
+  s.email = "dan@kallistec.com".freeze
+  s.extra_rdoc_files = ["LICENSE".freeze, "README.md".freeze]
+  s.files = ["CHANGELOG".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "lib/deep_merge.rb".freeze, "lib/deep_merge/core.rb".freeze, "lib/deep_merge/deep_merge_hash.rb".freeze, "lib/deep_merge/rails_compat.rb".freeze, "test/test_deep_merge.rb".freeze]
+  s.homepage = "https://github.com/danielsdeleo/deep_merge".freeze
+  s.licenses = ["MIT".freeze]
+  s.rubygems_version = "3.2.5".freeze
+  s.summary = "Merge Deeply Nested Hashes".freeze
+  s.test_files = ["test/test_deep_merge.rb".freeze]
 
   if s.respond_to? :specification_version then
     s.specification_version = 4
+  end
 
-    if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
-      s.add_development_dependency(%q<rake>, ["~> 10.1"])
-      s.add_development_dependency(%q<test-unit-minitest>, [">= 0"])
-    else
-      s.add_dependency(%q<rake>, ["~> 10.1"])
-      s.add_dependency(%q<test-unit-minitest>, [">= 0"])
-    end
+  if s.respond_to? :add_runtime_dependency then
+    s.add_development_dependency(%q<rake>.freeze, ["~> 10.1"])
+    s.add_development_dependency(%q<test-unit-minitest>.freeze, [">= 0"])
   else
-    s.add_dependency(%q<rake>, ["~> 10.1"])
-    s.add_dependency(%q<test-unit-minitest>, [">= 0"])
+    s.add_dependency(%q<rake>.freeze, ["~> 10.1"])
+    s.add_dependency(%q<test-unit-minitest>.freeze, [">= 0"])
   end
 end
diff --git a/lib/deep_merge/core.rb b/lib/deep_merge/core.rb
index c284fe3..0abc1ba 100644
--- a/lib/deep_merge/core.rb
+++ b/lib/deep_merge/core.rb
@@ -34,6 +34,8 @@ module DeepMerge
   #      Set to string value to run "Array::join" then "String::split" against all arrays
   #   :merge_hash_arrays      DEFAULT: false
   #      Set to true to merge hashes within arrays
+  #   :keep_array_duplicates  DEFAULT: false
+  #      Set to true to preserve duplicate array entries
   #   :merge_debug            DEFAULT: false
   #      Set to true to get console output of merge process for debugging
   #
@@ -64,7 +66,13 @@ module DeepMerge
   #   dest   = {:x => [{:z => 2}]}
   #   dest.deep_merge!(source, {:merge_hash_arrays => true})
   #   Results: {:x => [{:y => 1, :z => 2}]}
-  # 
+  #
+  # :keep_array_duplicates => merges arrays within hashes but keeps duplicate elements
+  #   source = {:x => {:y => [1,2,2,2,3]}}
+  #   dest   = {:x => {:y => [4,5,6]}}
+  #   dest.deep_merge!(source, {:keep_array_duplicates => true})
+  #   Results: {:x => {:y => [1,2,2,2,3,4,5,6]}}
+  #
   # There are many tests for this library - and you can learn more about the features
   # and usages of deep_merge! by just browsing the test examples
   def self.deep_merge!(source, dest, options = {})
@@ -84,10 +92,14 @@ module DeepMerge
     merge_hash_arrays = options[:merge_hash_arrays] || false
     # request to extend existing arrays, instead of overwriting them
     extend_existing_arrays = options[:extend_existing_arrays] || false
+    # request that arrays keep duplicate elements
+    keep_array_duplicates = options[:keep_array_duplicates] || false
+    # request that nil values are merged or skipped (Skipped/false by default)
+    merge_nil_values = options[:merge_nil_values] || false
 
     di = options[:debug_indent] || ''
     # do nothing if source is nil
-    return dest if source.nil?
+    return dest if !merge_nil_values && source.nil?
     # if dest doesn't exist, then simply copy source to it
     if !(dest) && overwrite_unmergeable
       dest = source; return dest
@@ -110,6 +122,11 @@ module DeepMerge
             rescue TypeError
               src_dup = src_value
             end
+            if src_dup.kind_of?(Array) && keep_array_duplicates
+              # note: in this case the merge will be additive, rather than a bounded set, so we can't simply merge src with itself
+              # We need to merge src with an empty array
+              src_dup = []
+            end
             dest[src_key] = deep_merge!(src_value, src_dup, options.merge(:debug_indent => di + '  '))
           end
         elsif dest.kind_of?(Array) && extend_existing_arrays
@@ -168,6 +185,8 @@ module DeepMerge
             end
             list += source[dest.count..-1] if source.count > dest.count
             dest = list
+          elsif keep_array_duplicates
+            dest = dest.concat(source)
           else
             dest = dest | source
           end
diff --git a/test/test_deep_merge.rb b/test/test_deep_merge.rb
index 3d4d2be..7551150 100644
--- a/test/test_deep_merge.rb
+++ b/test/test_deep_merge.rb
@@ -622,5 +622,30 @@ class TestDeepMerge < Test::Unit::TestCase
     hash_src = {"item" => s2 }
     DeepMerge::deep_merge!(hash_src, hash_dst)
     assert_equal({"item" => ""}, hash_dst)
+
+    ######################################
+    # tests for "keep_array_duplicates" option
+    hash_src = {"item" => ["2", "3"]}
+    hash_dst = {"item" => ["1", "2"]}
+    DeepMerge::deep_merge!(hash_src, hash_dst, {:keep_array_duplicates => true})
+    assert_equal({"item" => ["1", "2", "2", "3"]}, hash_dst)
+
+    # For Issue 34 - keep_array_duplicates against a nil src doesn't do a recursive merge
+    hash_src = {"item" => ["2", "3"]}
+    hash_dst = { }
+    DeepMerge::deep_merge!(hash_src, hash_dst, {:keep_array_duplicates => true})
+    assert_equal({"item" => ["2", "3"]}, hash_dst)
+
+    # Don't merge nil values by default
+    hash_src = {"item" => nil}
+    hash_dst = {"item" => "existing"}
+    DeepMerge::deep_merge!(hash_src, hash_dst)
+    assert_equal({"item" => "existing"}, hash_dst)
+
+    # Merge nil values via an explicit: :merge_nil_values => true
+    hash_src = {"item" => nil}
+    hash_dst = {"item" => "existing"}
+    DeepMerge::deep_merge!(hash_src, hash_dst, {:merge_nil_values => true})
+    assert_equal({"item" => nil}, hash_dst)
   end # test_deep_merge
 end

Debdiff

[The following lists of changes regard files as different if they have different names, permissions or owners.]

Files in second set of .debs but not in first

-rw-r--r--  root/root   /usr/share/rubygems-integration/all/specifications/deep_merge-1.2.2.gemspec

Files in first set of .debs but not in second

-rw-r--r--  root/root   /usr/share/rubygems-integration/all/specifications/deep_merge-1.1.1.gemspec

No differences were encountered in the control files

More details

Full run details