Sha256: 73e0ae6e4a7ad3b2ecb02b34d797c14642602aa1866e62d8bc1656a50755e152

Contents?: true

Size: 986 Bytes

Versions: 17

Compression:

Stored size: 986 Bytes

Contents

# frozen_string_literal: true

# The conditions approach is only available in Rails 3. This behaviour is
# superseded by ScopedReflection for Rails 4.0.
class ThinkingSphinx::ActiveRecord::Depolymorph::ConditionsReflection <
  ThinkingSphinx::ActiveRecord::Depolymorph::BaseReflection

  def call
    klass.new reflection.macro, name, options, active_record
  end

  private

  delegate :foreign_type, :active_record, :to => :reflection

  def condition
    "::ts_join_alias::.#{quoted_foreign_type} = '#{class_name}'"
  end

  def options
    super

    case @options[:conditions]
    when nil
      @options[:conditions] = condition
    when Array
      @options[:conditions] << condition
    when Hash
      @options[:conditions].merge! foreign_type => @options[:class_name]
    else
      @options[:conditions] = "#{@options[:conditions]} AND #{condition}"
    end

    @options
  end

  def quoted_foreign_type
    active_record.connection.quote_column_name foreign_type
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

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