Class: ThinkingSphinx::ActiveRecord::SQLSource

Inherits:
Riddle::Configuration::SQLSource
  • Object
show all
Includes:
Core::Settings
Defined in:
lib/thinking_sphinx/active_record/sql_source.rb

Defined Under Namespace

Classes: Template

Constant Summary

OPTIONS =
[:name, :offset, :delta_processor, :delta?, :disable_range?,
:group_concat_max_len, :utf8?, :position]

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (SQLSource) initialize(model, options = {})

Returns a new instance of SQLSource



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 12

def initialize(model, options = {})
  @model             = model
  @database_settings = ::ActiveRecord::Base.connection.
    instance_variable_get(:@config).clone
  @options           = {
    :utf8? => (@database_settings[:encoding] == 'utf8')
  }.merge options

  @fields            = []
  @attributes        = []
  @associations      = []
  @conditions        = []
  @groupings         = []
  @polymorphs        = []

  Template.new(self).apply

  name = "#{options[:name] || model.name.downcase}_#{options[:position]}"

  super name, type

  apply_defaults!
end

Instance Attribute Details

- (Object) associations

Returns the value of attribute associations



6
7
8
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 6

def associations
  @associations
end

- (Object) attributes

Returns the value of attribute attributes



6
7
8
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 6

def attributes
  @attributes
end

- (Object) conditions

Returns the value of attribute conditions



6
7
8
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 6

def conditions
  @conditions
end

- (Object) database_settings (readonly)

Returns the value of attribute database_settings



5
6
7
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 5

def database_settings
  @database_settings
end

- (Object) fields

Returns the value of attribute fields



6
7
8
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 6

def fields
  @fields
end

- (Object) groupings

Returns the value of attribute groupings



6
7
8
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 6

def groupings
  @groupings
end

- (Object) model (readonly)

Returns the value of attribute model



5
6
7
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 5

def model
  @model
end

- (Object) options (readonly)

Returns the value of attribute options



5
6
7
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 5

def options
  @options
end

- (Object) polymorphs

Returns the value of attribute polymorphs



6
7
8
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 6

def polymorphs
  @polymorphs
end

Instance Method Details

- (Object) adapter



36
37
38
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 36

def adapter
  @adapter ||= DatabaseAdapters.adapter_for(@model)
end

- (Boolean) delta?

Returns:

  • (Boolean)


44
45
46
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 44

def delta?
  options[:delta?]
end

- (Object) delta_processor



40
41
42
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 40

def delta_processor
  options[:delta_processor].try(:new, adapter)
end

- (Boolean) disable_range?

Returns:

  • (Boolean)


48
49
50
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 48

def disable_range?
  options[:disable_range?]
end

- (Object) facets



52
53
54
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 52

def facets
  properties.select(&:facet?)
end

- (Object) offset



56
57
58
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 56

def offset
  options[:offset]
end

- (Object) primary_key



60
61
62
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 60

def primary_key
  options[:primary_key]
end

- (Object) render



64
65
66
67
68
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 64

def render
  prepare_for_render unless @prepared

  super
end

- (Object) type



70
71
72
73
74
75
76
77
78
79
# File 'lib/thinking_sphinx/active_record/sql_source.rb', line 70

def type
  @type ||= case adapter
  when DatabaseAdapters::MySQLAdapter
    'mysql'
  when DatabaseAdapters::PostgreSQLAdapter
    'pgsql'
  else
    raise "Unknown Adapter Type: #{adapter.class.name}"
  end
end