Class: Tagalong::TagManager

Inherits:
Object
  • Object
show all
Defined in:
lib/tagalong/tag_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(taggable, tagger) ⇒ TagManager

Returns a new instance of TagManager.



3
4
5
6
# File 'lib/tagalong/tag_manager.rb', line 3

def initialize(taggable, tagger)
  @taggable = taggable
  @tagger = tagger
end

Instance Method Details

#add_tag(name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/tagalong/tag_manager.rb', line 8

def add_tag(name)
  tagger_tag = tagger_used_tag?(name)
  if (tagger_tag != nil)
    if !taggable_has_tag?(name)
      associate_tag_with_taggable(tagger_tag, @taggable)
    end
  else
    tagger_tag = create_tag_for_tagger(name, @tagger)
    associate_tag_with_taggable(tagger_tag, @taggable)
  end
end

#remove_tag(name) ⇒ Object



20
21
22
23
24
25
# File 'lib/tagalong/tag_manager.rb', line 20

def remove_tag(name)
  tagger_tag = tagger_used_tag?(name)
  if tagger_tag && taggable_has_tag?(name)
    disassociate_tag_from_taggable(tagger_tag, @taggable)
  end
end

#taggable_has_tag?(name) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/tagalong/tag_manager.rb', line 31

def taggable_has_tag?(name)
  @taggable.tagalong_tags.find_by_name(name)
end

#tagger_used_tag?(name) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/tagalong/tag_manager.rb', line 27

def tagger_used_tag?(name)
  @tagger.tagalong_tags.find_by_name(name)
end