lib/picky/indexes.rb in picky-2.7.0 vs lib/picky/indexes.rb in picky-3.0.0.pre1

- old
+ new

@@ -1,75 +1,82 @@ -# Holds all indexes and provides operations -# for extracting and working on them. -# -# Delegates a number of operations to the -# indexes. -# -class Indexes +module Picky - attr_reader :indexes, - :index_mapping + # Holds all indexes and provides operations + # for extracting and working on them. + # + # Delegates a number of operations to the + # indexes. + # + class Indexes - delegate :size, - :each, - :to => :indexes + attr_reader :indexes, + :index_mapping - each_delegate :reindex, - :each_category, - :to => :indexes + delegate :size, + :each, + :to => :indexes - def initialize - clear_indexes - end + each_delegate :reindex, + :each_category, + :to => :indexes - # Return the Indexes instance. - # - def self.instance - @instance ||= new - end + def initialize + clear_indexes + end - instance_delegate :clear, - :register, - :reindex, - :[], - :to_s, - :size, - :each, - :each_category + # Return the Indexes instance. + # + def self.instance + @instance ||= new + end + def self.identifier + name + end - # Clears the indexes and the mapping. - # - def clear_indexes - @indexes = [] - @index_mapping = {} - end + instance_delegate :clear, + :register, + :reindex, + :[], + :to_s, + :size, + :each, + :each_category - # Registers an index with the indexes. - # - def register index - self.indexes << index - self.index_mapping[index.name] = index - end - def self.register index - self.instance.register index - end + # Clears the indexes and the mapping. + # + def clear_indexes + @indexes = [] + @index_mapping = {} + end - # Extracts an index, given its identifier. - # - def [] identifier - index_name = identifier.to_sym - index_mapping[index_name] || raise_not_found(index_name) - end + # Registers an index with the indexes. + # + def register index + self.indexes << index + self.index_mapping[index.name] = index + end + def self.register index + self.instance.register index + end - # Raises a not found for the index. - # - def raise_not_found index_name - raise %Q{Index "#{index_name}" not found. Possible indexes: "#{indexes.map(&:name).join('", "')}".} - end + # Extracts an index, given its identifier. + # + def [] identifier + index_name = identifier.to_sym + index_mapping[index_name] || raise_not_found(index_name) + end - # - # - def to_s - indexes.indented_to_s + # Raises a not found for the index. + # + def raise_not_found index_name + raise %Q{Index "#{index_name}" not found. Possible indexes: "#{indexes.map(&:name).join('", "')}".} + end + + # + # + def to_s + indexes.indented_to_s + end + end end \ No newline at end of file