Skip to content

Instantly share code, notes, and snippets.

@FestivalBobcats
Created October 12, 2011 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save FestivalBobcats/1282702 to your computer and use it in GitHub Desktop.
Save FestivalBobcats/1282702 to your computer and use it in GitHub Desktop.
# 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