class ThinkingSphinx::AbstractAdapter

Public Class Methods

adapter_for_model(model) click to toggle source
# File lib/thinking_sphinx/adapters/abstract_adapter.rb, line 26
def self.adapter_for_model(model)
  case ThinkingSphinx.database_adapter
  when String
    ThinkingSphinx.database_adapter.to_sym
  when NilClass
    standard_adapter_for_model model
  when Proc
    ThinkingSphinx.database_adapter.call model
  else
    ThinkingSphinx.database_adapter
  end
end
detect(model) click to toggle source
# File lib/thinking_sphinx/adapters/abstract_adapter.rb, line 12
def self.detect(model)
  adapter = adapter_for_model model
  case adapter
  when :mysql
    ThinkingSphinx::MysqlAdapter.new model
  when :postgresql
    ThinkingSphinx::PostgreSQLAdapter.new model
  when Class
    adapter.new model
  else
    raise "Invalid Database Adapter: Sphinx only supports MySQL and PostgreSQL, not #{adapter}"
  end
end
new(model) click to toggle source
# File lib/thinking_sphinx/adapters/abstract_adapter.rb, line 3
def initialize(model)
  @model = model
end
standard_adapter_for_model(model) click to toggle source
# File lib/thinking_sphinx/adapters/abstract_adapter.rb, line 39
def self.standard_adapter_for_model(model)
  case model.connection.class.name
  when "ActiveRecord::ConnectionAdapters::MysqlAdapter",
       "ActiveRecord::ConnectionAdapters::MysqlplusAdapter",
       "ActiveRecord::ConnectionAdapters::Mysql2Adapter",
       "ActiveRecord::ConnectionAdapters::NullDBAdapter"
    :mysql
  when "ActiveRecord::ConnectionAdapters::PostgreSQLAdapter"
    :postgresql
  when "ActiveRecord::ConnectionAdapters::JdbcAdapter"
    case model.connection.config[:adapter]
    when "jdbcmysql"
      :mysql
    when "jdbcpostgresql"
      :postgresql
    else
      model.connection.config[:adapter].to_sym
    end
  else
    model.connection.class.name
  end
end

Public Instance Methods

bigint_pattern() click to toggle source
# File lib/thinking_sphinx/adapters/abstract_adapter.rb, line 66
def bigint_pattern
  %rbigint/
end
case(expression, pairs, default) click to toggle source
# File lib/thinking_sphinx/adapters/abstract_adapter.rb, line 74
def case(expression, pairs, default)
  "CASE #{expression} " +
  pairs.keys.inject('') { |string, key|
    string + "WHEN '#{key}' THEN #{pairs[key]} "
  } + "ELSE #{default} END"
end
downcase(clause) click to toggle source
# File lib/thinking_sphinx/adapters/abstract_adapter.rb, line 70
def downcase(clause)
  "LOWER(#{clause})"
end
quote_with_table(column) click to toggle source
# File lib/thinking_sphinx/adapters/abstract_adapter.rb, line 62
def quote_with_table(column)
  "#{@model.quoted_table_name}.#{@model.connection.quote_column_name(column)}"
end
setup() click to toggle source
# File lib/thinking_sphinx/adapters/abstract_adapter.rb, line 7
def setup
  # Deliberately blank - subclasses should do something though. Well, if
  # they need to.
end

Protected Instance Methods

connection() click to toggle source
# File lib/thinking_sphinx/adapters/abstract_adapter.rb, line 83
def connection
  @connection ||= @model.connection
end