Refactor PropertyMerge to use Ruby's #uniq instead

This commit is contained in:
Pau Perez
2018-11-26 17:01:04 +01:00
parent 1363a2a17d
commit faac5f4b2d
2 changed files with 5 additions and 11 deletions

View File

@@ -26,6 +26,9 @@ module Spree
# When a Property is destroyed, dependent-destroy will destroy all ProductProperties,
# which will take care of refreshing the products cache
def property
self
end
private

View File

@@ -1,18 +1,9 @@
module OpenFoodNetwork
class PropertyMerge
def self.merge(primary, secondary)
primary + secondary.reject do |secondary_p|
primary.any? do |primary_p|
property_of(primary_p).presentation == property_of(secondary_p).presentation
end
(primary + secondary).uniq do |property_object|
property_object.property.presentation
end
end
private
def self.property_of(p)
p.respond_to?(:property) ? p.property : p
end
end
end