Sha256: a14811e68d15cb09b6fe927e1a8d9d9b85f43fc99724dfc29b56fd37c92a0251

Contents?: true

Size: 1.57 KB

Versions: 13

Compression:

Stored size: 1.57 KB

Contents

module Configuration
  class Type
    attr_reader :name,
                :source,
                :fields,
                :after_indexing,
                :result_type,
                :ignore_unassigned_tokens,
                :solr
    def initialize name, source, *fields, options
      if Configuration::Field === options
        fields << options
        options = {}
      end
      
      @name                     = name
      @source                   = source
                                  # dup, if field is reused. TODO Rewrite.
      @fields                   = fields.map { |field| field = field.dup; field.type = self; field }
      
      @after_indexing           = options[:after_indexing]
      @result_type              = options[:result_type] || name
      @ignore_unassigned_tokens = options[:ignore_unassigned_tokens] || false       # TODO Move to query?
      # @solr                     = options[:solr] || nil
    end
    def generate
      categories = fields.map { |field| field.generate }
      Index::Type.new name, result_type, ignore_unassigned_tokens, *categories
    end
    def take_snapshot
      source.take_snapshot self
    end
    def index
      fields.each do |field|
        field.index
      end
    end
    # def solr_fields
    #   solr ? fields.select { |field| !field.virtual? } : []
    # end
    # # TODO Delegate to Solr handler.
    # #
    # def index_solr
    #   return unless solr
    #   @indexer = Indexers::Solr.new self
    #   @indexer.index
    # end
    # TODO Spec!
    #
    def connect_backend
      @source.connect_backend
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
picky-0.10.5 lib/picky/configuration/type.rb
picky-0.10.4 lib/picky/configuration/type.rb
picky-0.10.2 lib/picky/configuration/type.rb
picky-0.10.1 lib/picky/configuration/type.rb
picky-0.10.0 lib/picky/configuration/type.rb
picky-0.9.4 lib/picky/configuration/type.rb
picky-0.9.3 lib/picky/configuration/type.rb
picky-0.9.2 lib/picky/configuration/type.rb
picky-0.9.1 lib/picky/configuration/type.rb
picky-0.9.0 lib/picky/configuration/type.rb
picky-0.3.0 lib/picky/configuration/type.rb
picky-0.2.4 lib/picky/configuration/type.rb
picky-0.2.3 lib/picky/configuration/type.rb