Class: ThinkingSphinx::AbstractAdapter
- Inherits:
-
Object
- Object
- ThinkingSphinx::AbstractAdapter
show all
- Defined in:
- lib/thinking_sphinx/adapters/abstract_adapter.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
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
.adapter_for_model(model) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
|
# 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) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# 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
|
.standard_adapter_for_model(model) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# 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]
end
else
model.connection.class.name
end
end
|
Instance Method Details
#bigint_pattern ⇒ Object
66
67
68
|
# File 'lib/thinking_sphinx/adapters/abstract_adapter.rb', line 66
def bigint_pattern
/bigint/i
end
|
#case(expression, pairs, default) ⇒ Object
74
75
76
77
78
79
|
# 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) ⇒ Object
70
71
72
|
# File 'lib/thinking_sphinx/adapters/abstract_adapter.rb', line 70
def downcase(clause)
"LOWER(#{clause})"
end
|
#quote_with_table(column) ⇒ Object
62
63
64
|
# 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 ⇒ Object
7
8
9
10
|
# File 'lib/thinking_sphinx/adapters/abstract_adapter.rb', line 7
def setup
end
|