# File lib/thinking_sphinx/active_record/sql_source.rb, line 74 def primary_key options[:primary_key] end
class ThinkingSphinx::ActiveRecord::SQLSource
Constants
- OPTIONS
Attributes
associations[RW]
attributes[RW]
conditions[RW]
fields[RW]
groupings[RW]
model[R]
options[R]
polymorphs[RW]
Public Class Methods
new(model, options = {})
click to toggle source
Calls superclass method
# File lib/thinking_sphinx/active_record/sql_source.rb, line 16 def initialize(model, options = {}) @model = model @options = { :utf8? => (database_settings[:encoding].to_s[/^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
Public Instance Methods
adapter()
click to toggle source
# File lib/thinking_sphinx/active_record/sql_source.rb, line 38 def adapter @adapter ||= DatabaseAdapters.adapter_for(@model) end
add_attribute(attribute)
click to toggle source
# File lib/thinking_sphinx/active_record/sql_source.rb, line 42 def add_attribute(attribute) attributes.delete_if { |existing| existing.name == attribute.name } attributes << attribute end
add_field(field)
click to toggle source
# File lib/thinking_sphinx/active_record/sql_source.rb, line 48 def add_field(field) fields.delete_if { |existing| existing.name == field.name } fields << field end
delta?()
click to toggle source
# File lib/thinking_sphinx/active_record/sql_source.rb, line 58 def delta? options[:delta?] end
delta_processor()
click to toggle source
# File lib/thinking_sphinx/active_record/sql_source.rb, line 54 def delta_processor options[:delta_processor].try(:new, adapter, @options[:delta_options] || {}) end
disable_range?()
click to toggle source
# File lib/thinking_sphinx/active_record/sql_source.rb, line 62 def disable_range? options[:disable_range?] end
facets()
click to toggle source
# File lib/thinking_sphinx/active_record/sql_source.rb, line 66 def facets properties.select(&:facet?) end
offset()
click to toggle source
# File lib/thinking_sphinx/active_record/sql_source.rb, line 70 def offset options[:offset] end
primary_key()
click to toggle source
properties()
click to toggle source
# File lib/thinking_sphinx/active_record/sql_source.rb, line 78 def properties fields + attributes end
render()
click to toggle source
Calls superclass method
# File lib/thinking_sphinx/active_record/sql_source.rb, line 82 def render prepare_for_render unless @prepared super end
set_database_settings(settings)
click to toggle source
# File lib/thinking_sphinx/active_record/sql_source.rb, line 88 def set_database_settings(settings) @sql_host ||= settings[:host] || 'localhost' @sql_user ||= settings[:username] || settings[:user] || ENV['USER'] @sql_pass ||= settings[:password].to_s.gsub('#', '\#') @sql_db ||= settings[:database] @sql_port ||= settings[:port] @sql_sock ||= settings[:socket] @mysql_ssl_cert ||= settings[:sslcert] @mysql_ssl_key ||= settings[:sslkey] @mysql_ssl_ca ||= settings[:sslca] end
type()
click to toggle source
# File lib/thinking_sphinx/active_record/sql_source.rb, line 100 def type @type ||= case adapter when DatabaseAdapters::MySQLAdapter 'mysql' when DatabaseAdapters::PostgreSQLAdapter 'pgsql' else raise UnknownDatabaseAdapter, "Provided type: #{adapter.class.name}" end end
Private Instance Methods
append_presenter_to_attribute_array()
click to toggle source
# File lib/thinking_sphinx/active_record/sql_source.rb, line 113 def append_presenter_to_attribute_array attributes.each do |attribute| presenter = Attribute::SphinxPresenter.new(attribute, self) attribute_array_for(presenter.collection_type) << presenter.declaration end end
attribute_array_for(type)
click to toggle source
# File lib/thinking_sphinx/active_record/sql_source.rb, line 121 def attribute_array_for(type) instance_variable_get "@sql_attr_#{type}".to_sym end
build_sql_fields()
click to toggle source
# File lib/thinking_sphinx/active_record/sql_source.rb, line 129 def build_sql_fields fields.each do |field| @sql_field_string << field.name if field.with_attribute? @sql_field_str2wordcount << field.name if field.wordcount? @sql_file_field << field.name if field.file? @sql_joined_field << PropertyQuery.new(field, self).to_s if field.source_type end end
build_sql_query()
click to toggle source
# File lib/thinking_sphinx/active_record/sql_source.rb, line 139 def build_sql_query @sql_query = builder.sql_query @sql_query_range ||= builder.sql_query_range @sql_query_pre += builder.sql_query_pre end
builder()
click to toggle source
# File lib/thinking_sphinx/active_record/sql_source.rb, line 125 def builder @builder ||= SQLBuilder.new self end
config()
click to toggle source
# File lib/thinking_sphinx/active_record/sql_source.rb, line 145 def config ThinkingSphinx::Configuration.instance end
database_settings()
click to toggle source
# File lib/thinking_sphinx/active_record/sql_source.rb, line 149 def database_settings @database_settings ||= begin if model.connection.respond_to?(:config) model.connection.config.clone else model.connection.instance_variable_get(:@config).clone end end end
prepare_for_render()
click to toggle source
# File lib/thinking_sphinx/active_record/sql_source.rb, line 159 def prepare_for_render polymorphs.each &:morph! append_presenter_to_attribute_array set_database_settings database_settings build_sql_fields build_sql_query @prepared = true end