deepsort 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/deepmerge.rb +46 -0
  3. metadata +2 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjdmMTc1ZGIxYjUxMDI4YzhkYjlhNzAzY2IzNjIyN2JlYzUwNGRhOA==
4
+ MDVjYTM4YjM4MzhlYWU2NTE1MjYzNTdiOWZiN2FiN2U0ZDE0M2E1YQ==
5
5
  data.tar.gz: !binary |-
6
- NzhmNDU0YzFjY2Q1MDE0YjIyOGE2NDQ0NDQ1MzdiZTA1MTQwNjg4Nw==
6
+ MzQ2MDU1ODBhYjgyZjUzY2NkMTQxOTkxZWQ5NzBkN2ExMmY1MGVlMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YWM4Y2RhYzBiMzQxOTM0MWUxM2Q1Y2IwZTM0NmU2MzVmMDRkOWUxMmNkODg5
10
- YzE2OTA4ZDliNDJjNjEzM2UwZmFlNTk1YTIxODE3NGIyYjg0MDY2NDllZTAz
11
- MWFiN2Q5ZGViNTI2MWU0ZThlMTczMDRlYWQ1OWM1NTc0N2ExMDI=
9
+ MDYyNzk4ODM5ZDQwYjBmNzI1MmY3ZjhmOTIwNTVmNmViZDA1NDlmMjAwZTg2
10
+ ZjczNjYzMWNiZGU4NjNiOTIzOGNjYzNjOTM5NTZkNjE5NDdiNmI5MDFkZDYx
11
+ OTlmZWFhYTk5YWIyNDQwNDQ2MzUxZjU5OGQyODdjOTNhNGRjNzI=
12
12
  data.tar.gz: !binary |-
13
- ZDk4NzAyOTE1YzZjMjkxNzFjZjQ2ZDUyYTY3MGJjMzE0OGM4Mjc5MjQ1MDJl
14
- YmY4MTM3ZjMzMTJmMjQyMGI3NWFlYjdmMjI1ZDFiZDhlZDE3ODY4NWNjY2M1
15
- Yzg3ZTU1ZDE3OTdlZmJlOGYwMDk4ZTZiYWJmMTMxZGNlNzc1MTk=
13
+ ODc2MWMzZWY3ZjhlY2VjZDY2MzZlNzdlZjM1MzRjYTg5YTg0ZGVhNjlkY2Rl
14
+ NTQyNGI5Yjg1NjJmMDJmMGMzNjc1OWViYzZjYzU4MGZmYzVjMjc4ZGU0Njdl
15
+ OGRkYTFhM2VkMTI1Yjg2ODNhOGQ0YmU4MjY0MDE4ZjBiNDM0YjM=
@@ -0,0 +1,46 @@
1
+ ### Deep Merge Utility
2
+ ## Over View
3
+ # when included into a project, this utility gives Arrays and Hashes the ability to deeply merge with other arrays and hashes
4
+ # instead of shallow merges, deep_merge recursively merges each nested array and hash.
5
+ # this does mean that the hashes and arrays must have similar structures.
6
+
7
+ module DeepMerge
8
+ # inject this method into the Array class to add deep merging functionality to Arrays
9
+ module DeepMergeArray
10
+ def deep_merge(other)
11
+ (self+other).uniq
12
+ end
13
+
14
+ def deep_merge!(other)
15
+ # in ruby, uniq! returns nil if there are no changes unlike uniq which returns the array
16
+ # because of this uniq has to be used here with a replacement instead of uniq!
17
+ replace(concat(other).uniq)
18
+ end
19
+ end
20
+
21
+ # inject this method into the Hash class to add deep merge functionality to Hashes
22
+ module DeepMergeHash
23
+ def deep_merge(other)
24
+ merge(other) do |key, oldval, newval|
25
+ if oldval.respond_to? :deep_merge
26
+ oldval.deep_merge(newval)
27
+ else
28
+ newval
29
+ end
30
+ end
31
+ end
32
+
33
+ def deep_merge!(other)
34
+ merge!(other) do |key, oldval, newval|
35
+ if oldval.respond_to? :deep_merge!
36
+ oldval.deep_merge!(newval)
37
+ else
38
+ newval
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ Array.send(:include, DeepMerge::DeepMergeArray)
46
+ Hash.send(:include, DeepMerge::DeepMergeHash)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deepsort
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Crossen
@@ -16,6 +16,7 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
+ - lib/deepmerge.rb
19
20
  - lib/deepsort.rb
20
21
  homepage: https://github.com/mcrossen/deepsort
21
22
  licenses: