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
.default ⇒ Object
Returns the value of attribute default.
5
6
7
|
# File 'lib/thinking_sphinx/active_record/database_adapters.rb', line 5
def default
@default
end
|
Class Method Details
.adapter_for(model) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/thinking_sphinx/active_record/database_adapters.rb', line 7
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 ThinkingSphinx::InvalidDatabaseAdapter, "Invalid adapter '#{adapter}': Thinking Sphinx only supports MySQL and PostgreSQL."
end
klass.new model
end
|
.adapter_type_for(model) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/thinking_sphinx/active_record/database_adapters.rb', line 23
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
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/thinking_sphinx/active_record/database_adapters.rb', line 37
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
49
50
51
52
53
|
# File 'lib/thinking_sphinx/active_record/database_adapters.rb', line 49
def adapter_type_for_jdbc_plain(adapter, url)
return adapter unless match = /^jdbc:(?<adapter>mysql|postgresql):\/\//.match(url)
match[:adapter].to_sym
end
|