Sha256: 472543a7080f181a1fb2de997bbe876c7ac79bc0bf9c2fcb3dc2dd1205e1ada9

Contents?: true

Size: 991 Bytes

Versions: 5

Compression:

Stored size: 991 Bytes

Contents

class ThinkingSphinx::ActiveRecord::AssociationProxy::AttributeFinder
  def initialize(association)
    @association = association
  end

  def attribute
    attributes.detect { |attribute|
      ThinkingSphinx::ActiveRecord::AssociationProxy::AttributeMatcher.new(
        attribute, foreign_key
      ).matches?
    } or raise "Missing Attribute for Foreign Key #{foreign_key}"
  end

  private

  def attributes
    indices.collect(&:attributes).flatten
  end

  def configuration
    ThinkingSphinx::Configuration.instance
  end

  def foreign_key
    @foreign_key ||= reflection_target.foreign_key
  end

  def indices
    @indices ||= begin
      configuration.preload_indices
      configuration.indices_for_references(
        *ThinkingSphinx::IndexSet.reference_name(@association.klass)
      ).reject &:distributed?
    end
  end

  def reflection_target
    target = @association.reflection
    target = target.through_reflection if target.through_reflection
    target
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
thinking-sphinx-3.4.2 lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb
thinking-sphinx-3.4.1 lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb
thinking-sphinx-3.4.0 lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb
thinking-sphinx-3.3.0 lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb
thinking-sphinx-3.2.0 lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb