Sha256: c64a7e3a107e26d4feab755893112ca8d96c8e29f2f470c01f4d5ce0c0ca71cb

Contents?: true

Size: 1.9 KB

Versions: 17

Compression:

Stored size: 1.9 KB

Contents

module Indexing
  
  class Indexes
    
    attr_reader :indexes
    
    each_delegate :take_snapshot,
                  :generate_caches,
                  :backup_caches,
                  :restore_caches,
                  :check_caches,
                  :clear_caches,
                  :create_directory_structure,
                  :to => :indexes
    
    def initialize
      clear
    end
    
    # TODO Spec.
    #
    def clear
      @indexes = []
    end
    
    # TODO Spec. Superclass?
    #
    def register index
      self.indexes << index
    end
    
    # Runs the indexers in parallel (index + cache).
    #
    # TODO Spec.
    #
    def index randomly = true
      take_snapshot
      
      # Run in parallel.
      #
      timed_exclaim "INDEXING USING #{Cores.max_processors} PROCESSORS, IN #{randomly ? 'RANDOM' : 'GIVEN'} ORDER."
      Cores.forked self.indexes, { randomly: randomly } do |an_index|
        an_index.index
        an_index.cache
      end
      timed_exclaim "INDEXING FINISHED."
    end
    
    # For testing.
    #
    def index_for_tests
      take_snapshot
      
      self.indexes.each do |an_index|
        an_index.index
        an_index.cache
      end
    end
    
    # TODO Spec
    #
    def generate_index_only index_name, category_name
      found = find index_name, category_name
      found.index if found
    end
    def generate_cache_only index_name, category_name
      found = find index_name, category_name
      found.generate_caches if found
    end
    
    # TODO Spec
    #
    def find index_name, category_name
      index_name     = index_name.to_sym
      
      indexes.each do |index|
        next unless index.name == index_name
        
        found = index.categories.find category_name
        return found if found
      end
      
      raise %Q{Index "#{index_name}" not found. Possible indexes: "#{indexes.map(&:name).join('", "')}".}
    end
    
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
picky-1.2.3 lib/picky/indexing/indexes.rb
picky-1.2.2 lib/picky/indexing/indexes.rb
picky-1.2.1 lib/picky/indexing/indexes.rb
picky-1.2.0 lib/picky/indexing/indexes.rb
picky-1.1.7 lib/picky/indexing/indexes.rb
picky-1.1.6 lib/picky/indexing/indexes.rb
picky-1.1.5 lib/picky/indexing/indexes.rb
picky-1.1.4 lib/picky/indexing/indexes.rb
picky-1.1.3 lib/picky/indexing/indexes.rb
picky-1.1.2 lib/picky/indexing/indexes.rb
picky-1.1.1 lib/picky/indexing/indexes.rb
picky-1.1.0 lib/picky/indexing/indexes.rb
picky-1.0.0 lib/picky/indexing/indexes.rb
picky-0.12.3 lib/picky/indexing/indexes.rb
picky-0.12.2 lib/picky/indexing/indexes.rb
picky-0.12.1 lib/picky/indexing/indexes.rb
picky-0.12.0 lib/picky/indexing/indexes.rb