class ThinkingSphinx::ActiveRecord::SourceJoins

Attributes

model[R]
source[R]

Public Class Methods

call(model, source) click to toggle source
# File lib/thinking_sphinx/active_record/source_joins.rb, line 4
def self.call(model, source)
  new(model, source).call
end
new(model, source) click to toggle source
# File lib/thinking_sphinx/active_record/source_joins.rb, line 8
def initialize(model, source)
  @model, @source = model, source
end

Public Instance Methods

call() click to toggle source
# File lib/thinking_sphinx/active_record/source_joins.rb, line 12
def call
  append_specified_associations
  append_property_associations

  joins
end

Private Instance Methods

append_column_associations(column) click to toggle source
# File lib/thinking_sphinx/active_record/source_joins.rb, line 29
def append_column_associations(column)
  return if column.__stack.empty? or column_included_in_queries?(column)

  joins.add_join_to column.__stack if column_exists?(column)
end
append_property_associations() click to toggle source
# File lib/thinking_sphinx/active_record/source_joins.rb, line 23
def append_property_associations
  source.properties.collect(&:columns).each do |columns|
    columns.each { |column| append_column_associations column }
  end
end
append_specified_associations() click to toggle source
# File lib/thinking_sphinx/active_record/source_joins.rb, line 35
def append_specified_associations
  source.associations.reject(&:string?).each do |association|
    joins.add_join_to association.stack
  end
end
column_exists?(column) click to toggle source
# File lib/thinking_sphinx/active_record/source_joins.rb, line 41
def column_exists?(column)
  Joiner::Path.new(model, column.__stack).model
  true
rescue Joiner::AssociationNotFound
  false
end
column_included_in_queries?(column) click to toggle source

Use “first” here instead of a more intuitive flatten because flatten will also ask each column to become an Array and that will start to retrieve data.

# File lib/thinking_sphinx/active_record/source_joins.rb, line 65
def column_included_in_queries?(column)
  source_query_properties.collect(&:columns).collect(&:first).include?(column)
end
joins() click to toggle source
# File lib/thinking_sphinx/active_record/source_joins.rb, line 48
def joins
  @joins ||= begin
    joins = Joiner::Joins.new model
    if joins.respond_to?(:join_association_class)
      joins.join_association_class = ThinkingSphinx::ActiveRecord::JoinAssociation
    end
    joins
  end
end
source_query_properties() click to toggle source
# File lib/thinking_sphinx/active_record/source_joins.rb, line 58
def source_query_properties
  source.properties.select { |field| field.source_type == :query }
end