Module: Noah::Taggable

Included in:
Application, Configuration, Ephemeral, Host, Service, Token
Defined in:
lib/noah/taggable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(model) ⇒ Object



2
3
4
5
# File 'lib/noah/taggable.rb', line 2

def self.included(model)
  model.send :set, :tags, ::Noah::Tag
  model.send :index, :tags
end

Instance Method Details

#tag!(tag_name) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/noah/taggable.rb', line 7

def tag!(tag_name)
  case tag_name.class.to_s
  when "Array"
    tag_name.each do |t|
      my_tag = ::Noah::Tag.find_or_create(:name => t)
      tags << my_tag
      my_tag.members = self
    end
  else
    my_tag = ::Noah::Tag.find_or_create(:name => tag_name)
    tags << my_tag
    my_tag.members = self
  end
  self.save
end

#to_hashObject



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

def to_hash
  tag_arr = Array.new
  self.tags.sort.each {|t| tag_arr << t.name} if self.tags.size != 0
  super.merge(:tags => tag_arr)
end

#untag!(tag_name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/noah/taggable.rb', line 23

def untag!(tag_name)
  case tag_name.class.to_s
  when "Array"
    tag_name.each do |t|
      remove_tag(t)
    end
  else
    remove_tag(tag_name)
  end
  self.save
end