Created
October 12, 2011 21:33
-
-
Save FestivalBobcats/1282702 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Orig | |
def items options = Hash.new | |
products = true_category.descendant_products.available.visible | |
if options[:vendor] | |
products = products.by_vendor options[:vendor] | |
end | |
if options[:factor] | |
products = products.factored_by options[:factor] | |
end | |
if options[:filters] && options[:filters].any? | |
products = products.find_from_tags_and_vendors options[:filters] | |
end | |
if options[:ids] | |
products = products.select(:id) | |
end | |
products | |
end | |
# New | |
def items(options={}) | |
{ | |
:vendor => :by_vendor, | |
:factor => :factored_by, | |
:filters => :find_from_tags_and_vendors, | |
:ids => [ :select, :id ] | |
}.inject true_category.descendant_products.available.visible do |rel, opt, meth, arg| | |
!(val = options[opt]).blank? ? rel.send *[ meth, arg || val ] : rel | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment