Module: Mongoid::Tag::Meta::InstanceMethods
- Defined in:
- lib/mongoid_tag/meta.rb
Instance Method Summary collapse
- #add_meta_tag(context, tag, meta) ⇒ Object
- #add_meta_tags(context, tags) ⇒ Object
- #get_meta_for(context) ⇒ Object
- #get_weights_for(context) ⇒ Object
- #remove_meta_tags(context, tags) ⇒ Object
- #update_meta_tags(context, added = nil, removed = nil) ⇒ Object
Instance Method Details
#add_meta_tag(context, tag, meta) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/mongoid_tag/meta.rb', line 46 def (context, tag, ) old_tag = self..where(:name => tag, :context => context).first if old_tag old_tag..merge!() else self. << MetaTag.new(:name => tag, :count => 1, :context => context, :meta => ) end end |
#add_meta_tags(context, tags) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/mongoid_tag/meta.rb', line 55 def (context, ) .each do |tag| old_tag = self..where(:name => tag, :context => context).first if old_tag old_tag.count += 1 else self. << MetaTag.new(:name => tag, :count => 1, :context => context) end end end |
#get_meta_for(context) ⇒ Object
36 37 38 |
# File 'lib/mongoid_tag/meta.rb', line 36 def (context) .where(:context => context).map{|tag| [tag.name, tag..merge(:count => tag.count)]} end |
#get_weights_for(context) ⇒ Object
32 33 34 |
# File 'lib/mongoid_tag/meta.rb', line 32 def get_weights_for(context) .where(:context => context).map{|tag| [tag.name, tag.count]} end |
#remove_meta_tags(context, tags) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/mongoid_tag/meta.rb', line 66 def (context, ) .each do |tag| old_tag = self..where(:name => tag, :context => context).first old_tag.count -= 1 if old_tag && old_tag.count > 0 end end |
#update_meta_tags(context, added = nil, removed = nil) ⇒ Object
40 41 42 43 44 |
# File 'lib/mongoid_tag/meta.rb', line 40 def (context, added=nil, removed=nil) (context, added) if added (context, removed) if removed save end |