Sha256: e855487f19b30a081dcf889726df45a8fb698b12646d25d3f77d806ea78b7d57

Contents?: true

Size: 973 Bytes

Versions: 4

Compression:

Stored size: 973 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(
        *@association.klass.name.underscore.to_sym
      ).reject &:distributed?
    end
  end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
thinking-sphinx-3.1.4 lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb
thinking-sphinx-3.1.3 lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb
thinking-sphinx-3.1.2 lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb
thinking-sphinx-3.1.1 lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb