Module: LeanTag::Taggable::ClassMethods

Defined in:
lib/lean_tag/taggable.rb

Instance Method Summary collapse

Instance Method Details

#tagged_with(list, filter = "tags") ⇒ Object

Returns all records which include at least one of the passed tags



35
36
37
38
39
40
# File 'lib/lean_tag/taggable.rb', line 35

def tagged_with(list, filter="tags")
  list = list.split(LeanTag.config.delimiter) if list.is_a?(String)
  tag_ids = Tag.matches(list).pluck(:id)
  taggings = Tagging.where(record_type: self.name, tag_id: tag_ids).where(filter: filter)
  return self.where(id: taggings.select(:record_id).distinct)
end

#tags(filter = "tags") ⇒ Object

Get all tags used by this class



45
46
47
48
# File 'lib/lean_tag/taggable.rb', line 45

def tags(filter="tags")
  taggings = Tagging.where(record_type: self.name, filter: filter).where(filter: filter)
  return Tag.where(id: taggings.select(:tag_id).distinct)
end