Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

56 lines (45 sloc) 1.259 kb
module Picky
class Categories
attr_reader :categories, :category_hash
delegate :each,
:first,
:map,
:to => :categories
each_delegate :cache,
:dump,
:empty,
:inject,
:reindex,
:reset_backend,
:to => :categories
# A list of indexed categories.
#
def initialize options = {}
clear_categories
end
# Clears both the array of categories and the hash of categories.
#
def clear_categories
@categories = []
@category_hash = {}
end
# Add the given category to the list of categories.
#
def << category
categories << category
category_hash[category.name] = category
end
# Find a given category in the categories.
#
def [] category_name
category_name = category_name.intern
category_hash[category_name] || raise_not_found(category_name)
end
def raise_not_found category_name
raise %Q{Index category "#{category_name}" not found. Possible categories: "#{categories.map(&:name).join('", "')}".}
end
def to_s
"#{self.class}(#{categories.join(', ')})"
end
end
end
Jump to Line
Something went wrong with that request. Please try again.