Sha256: 1dd57a4f404c427f3434de4e246fd2c50bb9139f9901a5ef53e5f2ac6ecc4d6e

Contents?: true

Size: 1.41 KB

Versions: 7

Compression:

Stored size: 1.41 KB

Contents

module Configuration
  
  # Describes the container for all index configurations.
  #
  class Indexes
    
    attr_reader :types
    
    def initialize
      @types = []
    end
    
    #
    #
    def default_index
      Tokenizers::Index
    end
    
    # Delegates
    #
    delegate :removes_characters, :contracts_expressions, :stopwords, :splits_text_on, :normalizes_words, :removes_characters_after_splitting, :to => :default_index
    
    # TODO Rewrite all this configuration handling.
    #
    def type name, source, *fields
      new_type = Type.new name, source, *fields
      types << new_type
      ::Indexes.configuration ||= self
      
      generated = new_type.generate
      ::Indexes.add generated
      generated
    end
    def field name, options = {}
      Field.new name, options
    end
    
    #
    #
    def take_snapshot *type_names
      only_if_included_in type_names do |type|
        type.take_snapshot
      end
    end
    def index *type_names
      only_if_included_in type_names do |type|
        type.index
      end
    end
    def index_solr *type_names
      only_if_included_in type_names do |type|
        type.index_solr
      end
    end
    
    #
    #
    def only_if_included_in type_names = []
      type_names = types.map(&:name) if type_names.empty?
      types.each do |type|
        next unless type_names.include?(type.name)
        yield type
      end
    end
    
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
picky-0.3.0 lib/picky/configuration/indexes.rb
picky-0.2.4 lib/picky/configuration/indexes.rb
picky-0.2.3 lib/picky/configuration/indexes.rb
picky-0.2.2 lib/picky/configuration/indexes.rb
picky-0.2.1 lib/picky/configuration/indexes.rb
picky-0.2.0 lib/picky/configuration/indexes.rb
picky-0.1.0 lib/picky/configuration/indexes.rb