deepsort 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/deepmerge.rb +46 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDVjYTM4YjM4MzhlYWU2NTE1MjYzNTdiOWZiN2FiN2U0ZDE0M2E1YQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzQ2MDU1ODBhYjgyZjUzY2NkMTQxOTkxZWQ5NzBkN2ExMmY1MGVlMg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MDYyNzk4ODM5ZDQwYjBmNzI1MmY3ZjhmOTIwNTVmNmViZDA1NDlmMjAwZTg2
|
10
|
+
ZjczNjYzMWNiZGU4NjNiOTIzOGNjYzNjOTM5NTZkNjE5NDdiNmI5MDFkZDYx
|
11
|
+
OTlmZWFhYTk5YWIyNDQwNDQ2MzUxZjU5OGQyODdjOTNhNGRjNzI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODc2MWMzZWY3ZjhlY2VjZDY2MzZlNzdlZjM1MzRjYTg5YTg0ZGVhNjlkY2Rl
|
14
|
+
NTQyNGI5Yjg1NjJmMDJmMGMzNjc1OWViYzZjYzU4MGZmYzVjMjc4ZGU0Njdl
|
15
|
+
OGRkYTFhM2VkMTI1Yjg2ODNhOGQ0YmU4MjY0MDE4ZjBiNDM0YjM=
|
data/lib/deepmerge.rb
ADDED
@@ -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.
|
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:
|