Sha256: ef8b08664bb92eb4b203250b6b99bb2140c3da605111d75c6ff903ba85f9b4a5

Contents?: true

Size: 1008 Bytes

Versions: 8

Compression:

Stored size: 1008 Bytes

Contents

# frozen_string_literal: true

class ThinkingSphinx::ActiveRecord::Attribute::SphinxPresenter
  SPHINX_TYPES = {
    :integer   => :uint,
    :boolean   => :bool,
    :timestamp => :uint,
    :float     => :float,
    :string    => :string,
    :bigint    => :bigint,
    :ordinal   => :str2ordinal,
    :wordcount => :str2wordcount,
    :json      => :json
  }

  def initialize(attribute, source)
    @attribute, @source = attribute, source
  end

  def collection_type
    @attribute.multi? ? :multi : sphinx_type
  end

  def declaration
    if @attribute.multi?
      multi_declaration
    else
      @attribute.name
    end
  end

  def sphinx_type
    SPHINX_TYPES[@attribute.type]
  end

  private

  def multi_declaration
    case @attribute.source_type
    when :query, :ranged_query
      query
    else
      "#{sphinx_type} #{@attribute.name} from field"
    end
  end

  def query
    ThinkingSphinx::ActiveRecord::PropertyQuery.new(
      @attribute, @source, sphinx_type
    ).to_s
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
thinking-sphinx-5.6.0 lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
thinking-sphinx-5.5.1 lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
thinking-sphinx-5.5.0 lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
thinking-sphinx-5.4.0 lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
thinking-sphinx-5.3.0 lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
thinking-sphinx-5.2.1 lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
thinking-sphinx-5.2.0 lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
thinking-sphinx-5.1.0 lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb