Sha256: 9f79f87098f5b9c8542bbc203434411d05ae3359933952e66a8be854f9f443fc

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

module Indexed # :nodoc:all

  # Registers the indexes held at runtime, for queries.
  #
  class Indexes

    attr_reader :indexes, :index_mapping
    
    each_delegate :load_from_cache,
                  :to => :indexes

    def initialize
      clear
    end
    
    # Reloads all indexes, one after another,
    # in the order they were added.
    #
    alias reload load_from_cache

    def to_s
      indexes.indented_to_s
    end

    # Clears the indexes and the mapping.
    #
    def clear
      @indexes       = []
      @index_mapping = {}
    end

    # Registers an index with the indexes.
    #
    def register index
      self.indexes << index
      self.index_mapping[index.name] = index
    end

    # Load each index, and analyze it.
    #
    # Returns a hash with the findings.
    #
    def analyze
      result = {}
      self.indexes.each do |index|
        index.analyze result
      end
      result
    end

    # Extracts an index, given its identifier.
    #
    def [] identifier
      index_mapping[identifier.to_sym]
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
picky-2.5.2 lib/picky/indexed/indexes.rb
picky-2.5.1 lib/picky/indexed/indexes.rb