From a50ae3f8ce9b36eeea247c6004139e717303f570 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Fri, 18 Oct 2019 10:37:23 +0100 Subject: [PATCH] Clarify the API of product_set class by making all other methods to private --- app/models/spree/product_set.rb | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/app/models/spree/product_set.rb b/app/models/spree/product_set.rb index e4c3eac1fb..e1c38951c4 100644 --- a/app/models/spree/product_set.rb +++ b/app/models/spree/product_set.rb @@ -3,6 +3,20 @@ class Spree::ProductSet < ModelSet super(Spree::Product, [], attributes, proc { |attrs| attrs[:product_id].blank? }) end + def save + @collection_hash.each_value.all? do |product_attributes| + update_attributes(product_attributes) + end + end + + def collection_attributes=(attributes) + @collection = Spree::Product + .where(id: attributes.each_value.map { |product| product[:id] }) + @collection_hash = attributes + end + + private + # A separate method of updating products was required due to an issue with # the way Rails' assign_attributes and updates_attributes behave when # delegated attributes of a nested object are updated via the parent object @@ -116,16 +130,4 @@ class Spree::ProductSet < ModelSet report.add_tab(:variant_error, variant.errors.first) unless variant.valid? end end - - def collection_attributes=(attributes) - @collection = Spree::Product - .where(id: attributes.each_value.map { |product| product[:id] }) - @collection_hash = attributes - end - - def save - @collection_hash.each_value.all? do |product_attributes| - update_attributes(product_attributes) - end - end end