Module: Peregrine::Features::Taggable

Defined in:
lib/peregrine/features/taggable.rb

Overview

Provides methods for adding and removing tags to and from objects. This essentially provides yet another method for identifying and filtering various objects. Intended to be included in classes requiring this functionality.

Instance Method Summary collapse

Instance Method Details

#add_tags(*list) ⇒ Object Also known as: add_tag

Add the given tags to the object. Tags may be any kind of object. Tags identical to existing tags are ignored. Returns an array of all tags this object contains.



16
17
18
19
# File 'lib/peregrine/features/taggable.rb', line 16

def add_tags(*list)
  tags.push(*list).uniq!
  tags
end

#remove_tags!(*list) ⇒ Object Also known as: remove_tag!

Removes the given tags from the object. Returns an array of the removed tags.



24
25
26
27
28
# File 'lib/peregrine/features/taggable.rb', line 24

def remove_tags!(*list)
  removed = []
  tags.reject! { |tag| list.include?(tag) ? removed.push(tag) : false }
  removed
end

#tagsObject

Returns the array of tags this object contains. Lazily evaluated.



9
10
11
# File 'lib/peregrine/features/taggable.rb', line 9

def tags
  @tags ||= []
end