Reduce assignment branching and complexity for ProductsRenderer#products

This commit is contained in:
Matt-Yorkley
2019-10-07 10:13:21 +01:00
parent 573a69477f
commit f2affe80cd

View File

@@ -35,15 +35,20 @@ module OpenFoodNetwork
return unless order_cycle
@products ||= begin
scoper = ScopeProductToHub.new(distributor)
results = distributed_products.products_relation.order(taxon_order)
distributed_products.products_relation.
order(taxon_order).
ransack(params[:q]).result.page(params[:page] || 1).per(params[:per_page] || 10).
each { |product| scoper.scope(product) }
filter_and_paginate(results).each { |product| product_scoper.scope(product) }
end
end
def product_scoper
ScopeProductToHub.new(distributor)
end
def filter_and_paginate(query)
query.ransack(params[:q]).result.page(params[:page] || 1).per(params[:per_page] || 10)
end
def distributed_products
OrderCycleDistributedProducts.new(distributor, order_cycle, customer)
end