Sha256: 8f1d653a6608b83faf458568c3cfed1353ee96ce26774096137ca4384944055e

Contents?: true

Size: 1.3 KB

Versions: 10

Compression:

Stored size: 1.3 KB

Contents

class ThinkingSphinx::Index
  attr_reader :reference, :options, :block

  def self.define(reference, options = {}, &block)
    new(reference, options, &block).indices.each do |index|
      ThinkingSphinx::Configuration.instance.indices << index
    end
  end

  def initialize(reference, options, &block)
    defaults = ThinkingSphinx::Configuration.instance.
      settings['index_options'] || {}
    defaults.symbolize_keys!

    @reference, @options, @block = reference, defaults.merge(options), block
  end

  def indices
    options[:delta] ? delta_indices : [single_index]
  end

  private

  def index_class
    case options[:with]
    when :active_record
      ThinkingSphinx::ActiveRecord::Index
    when :real_time
      ThinkingSphinx::RealTime::Index
    else
      raise "Unknown index type: #{options[:with]}"
    end
  end

  def single_index
    index_class.new(reference, options).tap do |index|
      index.definition_block = block
    end
  end

  def delta_indices
    [false, true].collect do |delta|
      index_class.new(
        reference,
        options.merge(:delta? => delta, :delta_processor => processor)
      ).tap do |index|
        index.definition_block = block
      end
    end
  end

  def processor
    @processor ||= ThinkingSphinx::Deltas.processor_for options.delete(:delta)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
thinking-sphinx-3.4.2 lib/thinking_sphinx/index.rb
thinking-sphinx-3.4.1 lib/thinking_sphinx/index.rb
thinking-sphinx-3.4.0 lib/thinking_sphinx/index.rb
thinking-sphinx-3.3.0 lib/thinking_sphinx/index.rb
thinking-sphinx-3.2.0 lib/thinking_sphinx/index.rb
thinking-sphinx-3.1.4 lib/thinking_sphinx/index.rb
thinking-sphinx-3.1.3 lib/thinking_sphinx/index.rb
thinking-sphinx-3.1.2 lib/thinking_sphinx/index.rb
thinking-sphinx-3.1.1 lib/thinking_sphinx/index.rb
thinking-sphinx-3.1.0 lib/thinking_sphinx/index.rb