Sha256: 4aee6334e95d49864ed25f3e65f960d05cc173d461d21fd3b673e1553982de1c

Contents?: true

Size: 957 Bytes

Versions: 12

Compression:

Stored size: 957 Bytes

Contents

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

  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

12 entries across 12 versions & 1 rubygems

Version Path
thinking-sphinx-3.1.3 lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
thinking-sphinx-3.1.2 lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
thinking-sphinx-3.1.1 lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
thinking-sphinx-3.1.0 lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
thinking-sphinx-3.0.6 lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
thinking-sphinx-3.0.5 lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
thinking-sphinx-3.0.4 lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
thinking-sphinx-3.0.3 lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
thinking-sphinx-3.0.2 lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
thinking-sphinx-3.0.1 lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
thinking-sphinx-3.0.0 lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb
thinking-sphinx-3.0.0.rc lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb