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



30
31
32
33
34
35
# File 'lib/lean_tag/taggable.rb', line 30

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



39
40
41
42
# File 'lib/lean_tag/taggable.rb', line 39

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