Sha256: b64f4b56310b6c2fc4378b839daf95018ed7340dc4a626fde0b36fb006a78b75

Contents?: true

Size: 1.4 KB

Versions: 9

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

class ThinkingSphinx::RealTime::Interpreter <
  ::ThinkingSphinx::Core::Interpreter

  def has(*columns)
    options = columns.extract_options!

    columns.collect { |column|
      ::ThinkingSphinx::RealTime::Attribute.new column, options
    }.each { |attribute| @index.add_attribute attribute }
  end

  def indexes(*columns)
    options = columns.extract_options!

    columns.collect { |column|
      ::ThinkingSphinx::RealTime::Field.new column, options
    }.each { |field| @index.add_field field }

    append_sortable_attributes columns, options if options[:sortable]
  end

  def scope(&block)
    @index.scope = block
  end

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

  def where(condition)
    @index.conditions << condition
  end

  private

  def append_sortable_attributes(columns, options)
    options = options.except(:sortable).merge(:type => :string)

    columns.collect { |column|
      aliased_name   = options[:as]
      aliased_name ||= column.__name.to_sym if column.respond_to?(:__name)
      aliased_name ||= column

      options[:as] = "#{aliased_name}_sort".to_sym

      ::ThinkingSphinx::RealTime::Attribute.new column, options
    }.each { |attribute| @index.add_attribute attribute }
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
thinking-sphinx-5.6.0 lib/thinking_sphinx/real_time/interpreter.rb
thinking-sphinx-5.5.1 lib/thinking_sphinx/real_time/interpreter.rb
thinking-sphinx-5.5.0 lib/thinking_sphinx/real_time/interpreter.rb
thinking-sphinx-5.4.0 lib/thinking_sphinx/real_time/interpreter.rb
thinking-sphinx-5.3.0 lib/thinking_sphinx/real_time/interpreter.rb
thinking-sphinx-5.2.1 lib/thinking_sphinx/real_time/interpreter.rb
thinking-sphinx-5.2.0 lib/thinking_sphinx/real_time/interpreter.rb
thinking-sphinx-5.1.0 lib/thinking_sphinx/real_time/interpreter.rb
thinking-sphinx-5.0.0 lib/thinking_sphinx/real_time/interpreter.rb