Sha256: 1fcf2402e45f213b852011057ba3280409e5dbab9257d525a2ba0f6b7f9a5d24

Contents?: true

Size: 522 Bytes

Versions: 1

Compression:

Stored size: 522 Bytes

Contents

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

1 entries across 1 versions & 1 rubygems

Version Path
gutentag-0.9.0 lib/gutentag/tagged_with/query.rb