class ActsAsTaggableOn::Taggable::TaggedWithQuery::QueryBase

Attributes

options[R]
tag_list[R]
tag_model[R]
taggable_model[R]
tagging_model[R]

Public Class Methods

new(taggable_model, tag_model, tagging_model, tag_list, options) click to toggle source
# File lib/acts_as_taggable_on/taggable/tagged_with_query/query_base.rb, line 3
def initialize(taggable_model, tag_model, tagging_model, tag_list, options)
  @taggable_model = taggable_model
  @tag_model      = tag_model
  @tagging_model  = tagging_model
  @tag_list       = tag_list
  @options        = options
end

Private Instance Methods

adjust_taggings_alias(taggings_alias) click to toggle source
# File lib/acts_as_taggable_on/taggable/tagged_with_query/query_base.rb, line 54
def adjust_taggings_alias(taggings_alias)
  if taggings_alias.size > 75
    taggings_alias = 'taggings_alias_' + Digest::SHA1.hexdigest(taggings_alias)
  end
  taggings_alias
end
escaped_tag(tag) click to toggle source
# File lib/acts_as_taggable_on/taggable/tagged_with_query/query_base.rb, line 49
def escaped_tag(tag)
  tag = tag.downcase unless ActsAsTaggableOn.strict_case_match
  tag.gsub(/[!%_]/) { |x| '!' + x }
end
tag_arel_table() click to toggle source
# File lib/acts_as_taggable_on/taggable/tagged_with_query/query_base.rb, line 19
def tag_arel_table
  @tag_arel_table ||= tag_model.arel_table
end
tag_match_type(tag) click to toggle source
# File lib/acts_as_taggable_on/taggable/tagged_with_query/query_base.rb, line 27
def tag_match_type(tag)
  matches_attribute = tag_arel_table[:name]
  matches_attribute = matches_attribute.lower unless ActsAsTaggableOn.strict_case_match

  if options[:wild].present?
    tag_arel_table[:name].matches("%#{escaped_tag(tag)}%", "!")
  else
    tag_arel_table[:name].matches(escaped_tag(tag), "!")
  end
end
taggable_arel_table() click to toggle source
# File lib/acts_as_taggable_on/taggable/tagged_with_query/query_base.rb, line 15
def taggable_arel_table
  @taggable_arel_table ||= taggable_model.arel_table
end
tagging_arel_table() click to toggle source
# File lib/acts_as_taggable_on/taggable/tagged_with_query/query_base.rb, line 23
def tagging_arel_table
  @tagging_arel_table ||=tagging_model.arel_table
end
tags_match_type() click to toggle source
# File lib/acts_as_taggable_on/taggable/tagged_with_query/query_base.rb, line 38
def tags_match_type
  matches_attribute = tag_arel_table[:name]
  matches_attribute = matches_attribute.lower unless ActsAsTaggableOn.strict_case_match

  if options[:wild].present?
    matches_attribute.matches_any(tag_list.map{|tag| "%#{escaped_tag(tag)}%"}, "!")
  else
    matches_attribute.matches_any(tag_list.map{|tag| "#{escaped_tag(tag)}"}, "!")
  end
end