lib/picky/categories.rb in picky-4.12.1 vs lib/picky/categories.rb in picky-4.12.2

- old
+ new

@@ -2,22 +2,22 @@ class Categories attr_reader :categories, :category_hash - delegate :each, - :first, - :map, - :to => :categories + forward :each, + :first, + :map, + :to => :categories - each_delegate :cache, - :dump, - :empty, - :inject, - :reindex, - :reset_backend, - :to => :categories + each_forward :cache, + :dump, + :empty, + :inject, + :reindex, + :reset_backend, + :to => :categories # A list of indexed categories. # def initialize options = {} clear_categories @@ -35,18 +35,24 @@ # Example: # You dynamically add a new category to an index. # To add the qualifiers to a search, you call this # method. # - def mapper - @mapper ||= QualifierMapper.new self + def qualifier_mapper + @qualifier_mapper ||= QualifierMapper.new self end + + # Resets the qualifier mapper used. + # + def reset_qualifier_mapper + @qualifier_mapper = nil + end # Add the given category to the list of categories. # def << category - @mapper = nil # TODO Move. (Resets category mapping) + reset_qualifier_mapper # TODO Have an add method on QualifierMapper? categories << category category_hash[category.name] = category end # Find a given category in the categories. @@ -55,9 +61,13 @@ 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_stats + map(&:name).join(', ') end def to_s "#{self.class}(#{categories.join(', ')})" end \ No newline at end of file