Module: ThinkingSphinx::ActiveRecord::DatabaseAdapters

Defined in:
lib/thinking_sphinx/active_record/database_adapters.rb

Defined Under Namespace

Classes: AbstractAdapter, MySQLAdapter, PostgreSQLAdapter

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.defaultObject

Returns the value of attribute default



3
4
5
# File 'lib/thinking_sphinx/active_record/database_adapters.rb', line 3

def default
  @default
end

Class Method Details

.adapter_for(model) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/thinking_sphinx/active_record/database_adapters.rb', line 5

def adapter_for(model)
  return default.new(model) if default

  adapter = adapter_type_for(model)
  klass   = case adapter
  when :mysql
    MySQLAdapter
  when :postgresql
    PostgreSQLAdapter
  else
    raise "Invalid Database Adapter '#{adapter}': Thinking Sphinx only supports MySQL and PostgreSQL."
  end

  klass.new model
end

.adapter_type_for(model) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/thinking_sphinx/active_record/database_adapters.rb', line 21

def adapter_type_for(model)
  class_name = model.connection.class.name
  case class_name.split('::').last
  when 'MysqlAdapter', 'Mysql2Adapter'
    :mysql
  when 'PostgreSQLAdapter'
    :postgresql
  when 'JdbcAdapter'
    adapter_type_for_jdbc(model)
  else
    class_name
  end
end

.adapter_type_for_jdbc(model) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/thinking_sphinx/active_record/database_adapters.rb', line 35

def adapter_type_for_jdbc(model)
  case adapter = model.connection.config[:adapter]
  when 'jdbcmysql'
    :mysql
  when 'jdbcpostgresql'
    :postgresql
  when 'jdbc'
    adapter_type_for_jdbc_plain(adapter, model.connection.config[:url])
  else adapter
  end
end

.adapter_type_for_jdbc_plain(adapter, url) ⇒ Object



47
48
49
50
51
# File 'lib/thinking_sphinx/active_record/database_adapters.rb', line 47

def adapter_type_for_jdbc_plain(adapter, url)
  return adapter unless match = /^jdbc:(?<adapter>mysql|postgresql):\/\//.match(url)

  match[:adapter].to_sym
end