Sha256: b693d51f2d355a6a4a4dd099bafcad352b22571e6635db33f4e3c4aba9238277

Contents?: true

Size: 1.06 KB

Versions: 17

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

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? ? escape_table(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_name)
    table_name.split('.').map { |t| adapter.quote(t) }.join('.')
  end

  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

17 entries across 17 versions & 1 rubygems

Version Path
thinking-sphinx-5.6.0 lib/thinking_sphinx/active_record/column_sql_presenter.rb
thinking-sphinx-5.5.1 lib/thinking_sphinx/active_record/column_sql_presenter.rb
thinking-sphinx-5.5.0 lib/thinking_sphinx/active_record/column_sql_presenter.rb
thinking-sphinx-5.4.0 lib/thinking_sphinx/active_record/column_sql_presenter.rb
thinking-sphinx-5.3.0 lib/thinking_sphinx/active_record/column_sql_presenter.rb
thinking-sphinx-5.2.1 lib/thinking_sphinx/active_record/column_sql_presenter.rb
thinking-sphinx-5.2.0 lib/thinking_sphinx/active_record/column_sql_presenter.rb
thinking-sphinx-5.1.0 lib/thinking_sphinx/active_record/column_sql_presenter.rb
thinking-sphinx-5.0.0 lib/thinking_sphinx/active_record/column_sql_presenter.rb
thinking-sphinx-4.4.1 lib/thinking_sphinx/active_record/column_sql_presenter.rb
thinking-sphinx-4.4.0 lib/thinking_sphinx/active_record/column_sql_presenter.rb
thinking-sphinx-4.3.2 lib/thinking_sphinx/active_record/column_sql_presenter.rb
thinking-sphinx-4.3.1 lib/thinking_sphinx/active_record/column_sql_presenter.rb
thinking-sphinx-4.3.0 lib/thinking_sphinx/active_record/column_sql_presenter.rb
thinking-sphinx-4.2.0 lib/thinking_sphinx/active_record/column_sql_presenter.rb
thinking-sphinx-4.1.0 lib/thinking_sphinx/active_record/column_sql_presenter.rb
thinking-sphinx-4.0.0 lib/thinking_sphinx/active_record/column_sql_presenter.rb