Sha256: f13259f889987a96a184085d6c3a5c29fdac27cb59a947301b9f408135af5e4c

Contents?: true

Size: 1.27 KB

Versions: 5

Compression:

Stored size: 1.27 KB

Contents

module Configuration
  
  # Describes the container for all index configurations.
  #
  class Indexes
    
    attr_reader :types
    
    def initialize
      @types = []
    end
    
    def default_tokenizer options = {}
      Tokenizers::Index.default = Tokenizers::Index.new(options)
    end
    
    # TODO Rewrite all this configuration handling.
    #
    def define_index 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

5 entries across 5 versions & 1 rubygems

Version Path
picky-0.10.5 lib/picky/configuration/indexes.rb
picky-0.10.4 lib/picky/configuration/indexes.rb
picky-0.10.2 lib/picky/configuration/indexes.rb
picky-0.10.1 lib/picky/configuration/indexes.rb
picky-0.10.0 lib/picky/configuration/indexes.rb