Sha256: 96f714ef0f63c5ea940af0d144bb08ced67d07d75a89edc4e6bdeab3828c13a2

Contents?: true

Size: 553 Bytes

Versions: 16

Compression:

Stored size: 553 Bytes

Contents

# frozen_string_literal: true

class Gutentag::TaggedWith::Query
  def initialize(model, values, match)
    @model  = model
    @values = Array values
    @match  = match
  end

  def call
    model.where "#{model_id} IN (#{query.to_sql})"
  end

  private

  attr_reader :model, :values, :match

  def model_id
    "#{model.quoted_table_name}.#{model.quoted_primary_key}"
  end

  def query
    return taggable_ids_query if match == :any || values.length == 1

    taggable_ids_query.having("COUNT(*) = #{values.length}").group(:taggable_id)
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
gutentag-2.5.4 lib/gutentag/tagged_with/query.rb
gutentag-2.5.3 lib/gutentag/tagged_with/query.rb
gutentag-2.5.2 lib/gutentag/tagged_with/query.rb
gutentag-2.5.1 lib/gutentag/tagged_with/query.rb
gutentag-2.5.0 lib/gutentag/tagged_with/query.rb
gutentag-2.4.1 lib/gutentag/tagged_with/query.rb
gutentag-2.4.0 lib/gutentag/tagged_with/query.rb
gutentag-2.3.2 lib/gutentag/tagged_with/query.rb
gutentag-2.3.1 lib/gutentag/tagged_with/query.rb
gutentag-2.3.0 lib/gutentag/tagged_with/query.rb
gutentag-2.2.1 lib/gutentag/tagged_with/query.rb
gutentag-2.2.0 lib/gutentag/tagged_with/query.rb
gutentag-2.1.0 lib/gutentag/tagged_with/query.rb
gutentag-2.0.0 lib/gutentag/tagged_with/query.rb
gutentag-1.1.0 lib/gutentag/tagged_with/query.rb
gutentag-1.0.0 lib/gutentag/tagged_with/query.rb