mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Refactor PropertyMerge to use Ruby's #uniq instead
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user