I have this method:
def self.get_image(product_id)
self.initialize
product_id=product_id.to_s
if @image_db.key?(product_id)
if Time.now.to_i - @image_db[product_id][':cached_at'] > @refresh_period
puts Time.now.to_i - @image_db[product_id][':cached_at']
self.cache_image(product_id)
else
return @image_db[product_id][':uri']
end
else
self.cache_image(product_id)
end
end
and I am getting rubocop errors to use a guard clause instead of an if
-else
statement. What would be the best way to do this?
I was contemplating this code:
def self.get_image(product_id)
self.initialize
product_id=product_id.to_s
return if @image_db.key?(product_id)
return if Time.now.to_i - @image_db[product_id][':cached_at'] > @refresh_period
puts Time.now.to_i - @image_db[product_id][':cached_at']
self.cache_image(product_id)
end
but this line would never be called:
return @image_db[product_id][':uri']