Module: FreezeTag::Taggable::ClassMethods

Defined in:
lib/freeze_tag/taggable.rb

Instance Method Summary collapse

Instance Method Details

#ever_freeze_tagged(as: nil, list: nil) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/freeze_tag/taggable.rb', line 88

def ever_freeze_tagged(as: nil, list: nil)
  as = as.downcase if self.try(:freeze_tag_case_sensitive)
  if list.present?
    self.joins("INNER JOIN freeze_tags ON freeze_tags.taggable_id = #{self.table_name}.id AND freeze_tags.tag = '#{as}' AND freeze_tags.list = '#{list}'").distinct("#{self.table_name}.id, *")
  else
    self.joins("INNER JOIN freeze_tags ON freeze_tags.taggable_id = #{self.table_name}.id AND freeze_tags.tag = '#{as}'").distinct("#{self.table_name}.id, *")
  end
end

#freeze_tagged(as: nil, list: nil) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/freeze_tag/taggable.rb', line 70

def freeze_tagged(as: nil, list: nil)
  as = as.downcase if self.try(:freeze_tag_case_sensitive)
  if list.present?
    self.joins("INNER JOIN freeze_tags ON freeze_tags.taggable_id = #{self.table_name}.id AND (freeze_tags.expired_at IS NULL OR freeze_tags.expired_at > '#{DateTime.now}') AND freeze_tags.tag = '#{as}' AND freeze_tags.list = '#{list}'").distinct("#{self.table_name}.id, *")
  else
    self.joins("INNER JOIN freeze_tags ON freeze_tags.taggable_id = #{self.table_name}.id AND (freeze_tags.expired_at IS NULL OR freeze_tags.expired_at > '#{DateTime.now}') AND freeze_tags.tag = '#{as}'").distinct("#{self.table_name}.id, *")
  end
end

#previously_freeze_tagged(as: nil, list: nil) ⇒ Object



79
80
81
82
83
84
85
86
# File 'lib/freeze_tag/taggable.rb', line 79

def previously_freeze_tagged(as: nil, list: nil)
  as = as.downcase if self.try(:freeze_tag_case_sensitive)
  if list.present?
    self.joins("INNER JOIN freeze_tags ON freeze_tags.taggable_id = #{self.table_name}.id AND freeze_tags.expired_at < '#{DateTime.now}' AND freeze_tags.tag = '#{as}' AND freeze_tags.list = '#{list}'").distinct("#{self.table_name}.id, *")
  else
    self.joins("INNER JOIN freeze_tags ON freeze_tags.taggable_id = #{self.table_name}.id AND freeze_tags.expired_at < '#{DateTime.now}' AND freeze_tags.tag = '#{as}'").distinct("#{self.table_name}.id, *")
  end
end