Module: MakeTaggable::Taggable::TaggedWithQuery Private

Defined in:
lib/make_taggable/taggable/tagged_with_query.rb,
lib/make_taggable/taggable/tagged_with_query/query_base.rb,
lib/make_taggable/taggable/tagged_with_query/all_tags_query.rb,
lib/make_taggable/taggable/tagged_with_query/any_tags_query.rb,
lib/make_taggable/taggable/tagged_with_query/exclude_tags_query.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Builds the relation behind Core::ClassMethods#tagged_with.

Defined Under Namespace

Classes: AllTagsQuery, AnyTagsQuery, ExcludeTagsQuery, QueryBase

Class Method Summary collapse

Class Method Details

.build(taggable_model, tag_model, tagging_model, tag_list, options) ⇒ ActiveRecord::Relation

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Picks the query strategy the options call for and builds the relation.

Parameters:

  • taggable_model (Class)

    the model being queried

  • tag_model (Class)

    the tag model

  • tagging_model (Class)

    the tagging model

  • tag_list (MakeTaggable::TagList)

    the tags to match

  • options (Hash)

    the options given to tagged_with

Returns:

  • (ActiveRecord::Relation)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/make_taggable/taggable/tagged_with_query.rb', line 24

def self.build(taggable_model, tag_model, tagging_model, tag_list, options)
  if options[:exclude].present? && options[:match_all].present?
    raise ArgumentError,
      ":match_all and :exclude cannot be combined. :match_all selects records carrying only the " \
      "given tags and nothing else, :exclude selects records carrying none of them, and there is " \
      "no set of records that satisfies both."
  end

  if options[:exclude].present?
    ExcludeTagsQuery.new(taggable_model, tag_model, tagging_model, tag_list, options).build
  elsif options[:any].present?
    AnyTagsQuery.new(taggable_model, tag_model, tagging_model, tag_list, options).build
  else
    AllTagsQuery.new(taggable_model, tag_model, tagging_model, tag_list, options).build
  end
end