| Module | BeTaggable::InstanceMethods |
| In: |
lib/be_taggable.rb
|
create new or overwrite tags, without touching overlapping tags.
# File lib/be_taggable.rb, line 48
48: def tag(str)
49: old_tags = tag_names
50: new_tags = self.class.split_tag_names(str)
51:
52: (new_tags - old_tags).each{|tag|
53: self.tags << Tag.find_or_create_by_name_and_model_type(tag, self.class.name)
54: }
55: (old_tags - new_tags).each{|tag|
56: tag_obj = Tag.find_by_name_and_model_type(tag, self.class.name)
57: self.tags.delete(tag_obj)
58: tag_obj.destroy if tag_obj.tagships_count == 1 # cached 1
59: }
60: update_attribute(:tags_cache, new_tags.to_yaml) if respond_to? :tags_cache
61: end