Sha256: dbe7dba8b5b3ccd5a5c8ff193613bb0d63b3437ac73e90f79d043b8f6c83f851

Contents?: true

Size: 892 Bytes

Versions: 17

Compression:

Stored size: 892 Bytes

Contents

# frozen_string_literal: true

class ThinkingSphinx::ActiveRecord::AssociationProxy::AttributeMatcher
    def initialize(attribute, foreign_key)
      @attribute, @foreign_key = attribute, foreign_key.to_s
    end

    def matches?
      return false if many?

      column_name_matches? || attribute_name_matches? || multi_singular_match?
    end

    private

    attr_reader :attribute, :foreign_key

    delegate :name, :multi?, :to => :attribute

    def attribute_name_matches?
      name == foreign_key
    end

    def column_name_matches?
      column.__name.to_s == foreign_key
    end

    def column
      attribute.respond_to?(:columns) ? attribute.columns.first :
        attribute.column
    end

    def many?
      attribute.respond_to?(:columns) && attribute.columns.many?
    end

    def multi_singular_match?
      multi? && name.singularize == foreign_key
    end
  end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
thinking-sphinx-5.6.0 lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb
thinking-sphinx-5.5.1 lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb
thinking-sphinx-5.5.0 lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb
thinking-sphinx-5.4.0 lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb
thinking-sphinx-5.3.0 lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb
thinking-sphinx-5.2.1 lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb
thinking-sphinx-5.2.0 lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb
thinking-sphinx-5.1.0 lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb
thinking-sphinx-5.0.0 lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb
thinking-sphinx-4.4.1 lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb
thinking-sphinx-4.4.0 lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb
thinking-sphinx-4.3.2 lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb
thinking-sphinx-4.3.1 lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb
thinking-sphinx-4.3.0 lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb
thinking-sphinx-4.2.0 lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb
thinking-sphinx-4.1.0 lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb
thinking-sphinx-4.0.0 lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb