Skip to content

Commit

Permalink
uniq compat for 1.8.7 on travis.
Browse files Browse the repository at this point in the history
  • Loading branch information
shaiguitar committed Jun 15, 2017
1 parent 7189f85 commit 0cb7a0e
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/fog/core/cache.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -284,4 +297,4 @@ def dump_to
name = "#{self.class.namespace(model.class, model.service)}/#{model.identity}-#{SecureRandom.hex}.yml"
end
end
end
end

0 comments on commit 0cb7a0e

Please sign in to comment.