Class: ThinkingSphinx::AbstractAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/thinking_sphinx/adapters/abstract_adapter.rb

Direct Known Subclasses

MysqlAdapter, PostgreSQLAdapter

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ AbstractAdapter

Returns a new instance of AbstractAdapter.



3
4
5
# File 'lib/thinking_sphinx/adapters/abstract_adapter.rb', line 3

def initialize(model)
  @model = model
end

Class Method Details

.detect(model) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/thinking_sphinx/adapters/abstract_adapter.rb', line 12

def self.detect(model)
  case model.connection.class.name
  when "ActiveRecord::ConnectionAdapters::MysqlAdapter",
       "ActiveRecord::ConnectionAdapters::MysqlplusAdapter"
    ThinkingSphinx::MysqlAdapter.new model
  when "ActiveRecord::ConnectionAdapters::PostgreSQLAdapter"
    ThinkingSphinx::PostgreSQLAdapter.new model
  when "ActiveRecord::ConnectionAdapters::JdbcAdapter"
    if model.connection.config[:adapter] == "jdbcmysql"
      ThinkingSphinx::MysqlAdapter.new model
    elsif model.connection.config[:adapter] == "jdbcpostgresql"
      ThinkingSphinx::PostgreSQLAdapter.new model
    else
      raise "Invalid Database Adapter: Sphinx only supports MySQL and PostgreSQL"
    end
  else
    raise "Invalid Database Adapter: Sphinx only supports MySQL and PostgreSQL, not #{model.connection.class.name}"
  end
end

Instance Method Details

#quote_with_table(column) ⇒ Object



32
33
34
# File 'lib/thinking_sphinx/adapters/abstract_adapter.rb', line 32

def quote_with_table(column)
  "#{@model.quoted_table_name}.#{@model.connection.quote_column_name(column)}"
end

#setupObject



7
8
9
10
# 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