Sha256: 99063d1743307cbb94950054e05f3ff0f142d1e4147feebfa5fcc0c1a2b00db4

Contents?: true

Size: 950 Bytes

Versions: 1

Compression:

Stored size: 950 Bytes

Contents

class ThinkingSphinx::ActiveRecord::ColumnSQLPresenter
  def initialize(model, column, adapter, associations)
    @model, @column, @adapter, @associations = model, column, adapter, associations
  end

  def aggregate?
    path.aggregate?
  rescue Joiner::AssociationNotFound
    false
  end

  def with_table
    return __name if string?
    return nil unless exists?

    quoted_table = escape_table? ? adapter.quote(table) : table

    "#{quoted_table}.#{adapter.quote __name}"
  end

  private

  attr_reader :model, :column, :adapter, :associations

  delegate :__stack, :__name, :string?, :to => :column

  def escape_table?
    table[/[`"]/].nil?
  end

  def exists?
    path.model.column_names.include?(column.__name.to_s)
  rescue Joiner::AssociationNotFound
    false
  end

  def path
    Joiner::Path.new model, column.__stack
  end

  def table
    associations.alias_for __stack
  end

  def version
    ActiveRecord::VERSION
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thinking-sphinx-3.1.4 lib/thinking_sphinx/active_record/column_sql_presenter.rb