Module: Mongoid::TagCollectible::Tagged::ClassMethods

Defined in:
lib/mongoid-tag-collectible/tagged.rb

Instance Method Summary collapse

Instance Method Details

#remove_tag!(tag_name) ⇒ Object



30
31
32
# File 'lib/mongoid-tag-collectible/tagged.rb', line 30

def remove_tag!(tag_name)
  self.collection.where({ tags: tag_name }).update({'$pull' => { tags: tag_name}}, multi: true)
end

#rename_tag!(old_tag, new_tag) ⇒ Object



25
26
27
28
# File 'lib/mongoid-tag-collectible/tagged.rb', line 25

def rename_tag!(old_tag, new_tag)
  self.collection.where({ tags: old_tag }).update({ '$addToSet' => { tags: new_tag }}, multi: true)
  self.remove_tag!(old_tag)
end