Module: DataMapper::Is::Taggable::InstanceMethods
- Defined in:
- lib/dm-is-taggable/is/taggable.rb
Overview
ClassMethods
Instance Method Summary collapse
Instance Method Details
#tag(tags) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/dm-is-taggable/is/taggable.rb', line 77 def tag() = [] unless .class == Array .each do |tag_name| tag_name = Tag.build(tag_name) if tag_name.class == String next if self.send("#{Extlib::Inflection::underscore(self.class.to_s)}_tags").first(:tag_id => tag_name.id, "#{Extlib::Inflection::underscore(self.class.to_s)}_id".intern => self.id) p = Extlib::Inflection::constantize("#{self.class.to_s}Tag").new(:tag => tag_name) self.send("#{Extlib::Inflection::underscore(self.class.to_s)}_tags") << p p.save unless self.new_record? end end |
#tags_list ⇒ Object
101 102 103 |
# File 'lib/dm-is-taggable/is/taggable.rb', line 101 def @tags_list || self..collect {|t| t.name}.join(", ") end |
#tags_list=(list) ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/dm-is-taggable/is/taggable.rb', line 105 def (list) @tags_list = list self..each {|t| self.untag(t) } # Tag list generation list = list.split(",").collect {|s| s.strip} # Do the tagging here list.each { |t| self.tag(Tag.build(t)) } end |
#untag(tags) ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/dm-is-taggable/is/taggable.rb', line 90 def untag() = [] unless .class == Array .each do |tag_name| tag_name = Tag.build(tag_name) if tag_name.class == String p = self.send("#{Extlib::Inflection::underscore(self.class.to_s)}_tags").first(:tag_id => tag_name.id) p.destroy if p end end |