Sha256: b2107e65c5ca65935df361c0c145b383792a0c838ff04f961b494516d121c1ac

Contents?: true

Size: 1.86 KB

Versions: 2

Compression:

Stored size: 1.86 KB

Contents

class ThinkingSphinx::ActiveRecord::Interpreter <
  ::ThinkingSphinx::Core::Interpreter

  def define_source(&block)
    @source = @index.append_source
    instance_eval &block
  end

  def group_by(*columns)
    __source.groupings += columns
  end

  def has(*columns)
    __source.attributes += build_properties(
      ::ThinkingSphinx::ActiveRecord::Attribute, columns
    )
  end

  def indexes(*columns)
    __source.fields += build_properties(
      ::ThinkingSphinx::ActiveRecord::Field, columns
    )
  end

  def join(*columns)
    __source.associations += columns.collect { |column|
      ::ThinkingSphinx::ActiveRecord::Association.new column
    }
  end

  def polymorphs(column, options)
    __source.polymorphs << ::ThinkingSphinx::ActiveRecord::Polymorpher.new(
      __source, column, options[:to]
    )
  end

  def sanitize_sql(*arguments)
    __source.model.send :sanitize_sql, *arguments
  end

  def set_database(hash_or_key)
    configuration = hash_or_key.is_a?(::Hash) ? hash_or_key.symbolize_keys :
      ::ActiveRecord::Base.configurations[hash_or_key.to_s]

    __source.set_database_settings configuration
  end

  def set_property(properties)
    properties.each do |key, value|
      @index.send("#{key}=", value)   if @index.class.settings.include?(key)
      __source.send("#{key}=", value) if __source.class.settings.include?(key)
      __source.options[key] = value   if source_option?(key)
      @index.options[key] = value     if search_option?(key)
    end
  end

  def where(*conditions)
    __source.conditions += conditions
  end

  private

  def __source
    @source ||= @index.append_source
  end

  def build_properties(klass, columns)
    options = columns.extract_options!
    columns.collect { |column| klass.new(__source.model, column, options) }
  end

  def source_option?(key)
    ::ThinkingSphinx::ActiveRecord::SQLSource::OPTIONS.include?(key)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
thinking-sphinx-3.1.3 lib/thinking_sphinx/active_record/interpreter.rb
thinking-sphinx-3.1.2 lib/thinking_sphinx/active_record/interpreter.rb