hash-joiner 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hash-joiner.rb +15 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90c7fec799df022cab292510997f96964ce21130
|
4
|
+
data.tar.gz: 7cc754bf27cee1b74e5c848ff58d1d6d63cea0af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83424ae89d14838c5aa17ea9691974d8c55df1ebbd63bc5b9a05afa97911ab385e09f267a9e9844d8ded1e1aacb57fcb5d013cfbf958c001c93cf3a1035f2786
|
7
|
+
data.tar.gz: fe45b74b525b1a4e5c7e2b1adfe3670097fa4bcf67308ee7b8a89350f253a343c456e2f04c5c5694b57df1aba2ad9aa70b4d0b04bdfbbe65b999f789e4b429df
|
data/lib/hash-joiner.rb
CHANGED
@@ -285,18 +285,30 @@ module HashJoiner
|
|
285
285
|
# Recursively prunes all empty properties from every element of a
|
286
286
|
# collection.
|
287
287
|
# @param collection [Hash<String>,Array<Hash<String>>] collection to update
|
288
|
-
# @param array_properties [Array<String>] list of properties to initialize
|
289
288
|
def self.prune_empty_properties(collection)
|
289
|
+
prune_empty_properties_helper(collection, {})
|
290
|
+
end
|
291
|
+
|
292
|
+
# Helper of prune_empty_properties that passes a object memoization table to
|
293
|
+
# recursive calls. The table prevents infinite recursion when objects
|
294
|
+
# contain cross-references to one another.
|
295
|
+
# @param collection [Hash<String>,Array<Hash<String>>] collection to update
|
296
|
+
# @param collection [Hash<String>] memoization table
|
297
|
+
# @return collection
|
298
|
+
def self.prune_empty_properties_helper(collection, seen_before)
|
299
|
+
return collection if seen_before[collection.object_id]
|
300
|
+
seen_before[collection.object_id] = true
|
290
301
|
if collection.instance_of? ::Hash
|
291
|
-
collection.each_value {|i|
|
302
|
+
collection.each_value {|i| prune_empty_properties_helper i, seen_before}
|
292
303
|
collection.delete_if do |unused_key, value|
|
293
304
|
(value.instance_of? ::Hash or value.instance_of? ::Array or
|
294
305
|
value.instance_of? ::String) and value.empty?
|
295
306
|
end
|
296
307
|
elsif collection.instance_of? ::Array
|
297
|
-
collection.each {|i|
|
308
|
+
collection.each {|i| prune_empty_properties_helper i, seen_before}
|
298
309
|
collection.delete_if {|i| i.empty?}
|
299
310
|
end
|
300
311
|
collection
|
301
312
|
end
|
313
|
+
private_class_method :prune_empty_properties_helper
|
302
314
|
end
|