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 2
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 6
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 10
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 27
def append_column_associations(column)
  return if column.__stack.empty?

  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 21
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 33
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 39
def column_exists?(column)
  Joiner::Path.new(model, column.__stack).model
  true
rescue Joiner::AssociationNotFound
  false
end
joins() click to toggle source
# File lib/thinking_sphinx/active_record/source_joins.rb, line 46
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