From 0cb7a0e5c8ae23bcc9822dca5c04167a9404946a Mon Sep 17 00:00:00 2001 From: Shai Rosenfeld Date: Thu, 15 Jun 2017 11:54:37 -0400 Subject: [PATCH] uniq compat for 1.8.7 on travis. --- lib/fog/core/cache.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/fog/core/cache.rb b/lib/fog/core/cache.rb index a1cbe8e..dd1a6df 100644 --- a/lib/fog/core/cache.rb +++ b/lib/fog/core/cache.rb @@ -130,7 +130,7 @@ def self.load(model_klass, service) # uniqe-ify based on the total of attributes. duplicate cache can exist due to # `model#identity` not being unique. but if all attributes match, they are unique # and shouldn't be loaded again. - uniq_loaded = loaded.uniq { |i| i.attributes } + uniq_loaded = uniq_w_block(loaded) { |i| i.attributes } if uniq_loaded.size != loaded.size Fog::Logger.warning("Found duplicate items in the cache. Expire all & refresh cache soon.") end @@ -160,6 +160,19 @@ def self.const_get_compat(strklass) end end + # :nodoc: compatability for 1.8.7 1.9.3 + def self.uniq_w_block(arr) + ret, keys = [], [] + arr.each do |x| + key = block_given? ? yield(x) : x + unless keys.include? key + ret << x + keys << key + end + end + ret + end + # method to determine if a path can be loaded and is valid fog cache format. def self.valid_for_load?(path) data = load_cache(path) @@ -284,4 +297,4 @@ def dump_to name = "#{self.class.namespace(model.class, model.service)}/#{model.identity}-#{SecureRandom.hex}.yml" end end -end +end \ No newline at end of file