Module: Mongoid::Document::Taggable::ClassMethods
- Defined in:
- lib/mongoid-simple-tags.rb
Instance Method Summary collapse
- #all_tags(scope = {}) ⇒ Object
- #scoped_tags(scope = {}) ⇒ Object
- #tag_list ⇒ Object
- #tagged_with(tags) ⇒ Object
- #tagged_with_all(tags) ⇒ Object
Instance Method Details
#all_tags(scope = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mongoid-simple-tags.rb', line 32 def (scope = {}) map = %Q{ function() { if(this.tags){ this.tags.forEach(function(tag){ emit(tag, 1) }); } } } reduce = %Q{ function(key, values) { var tag_count = 0 ; values.forEach(function(value) { tag_count += value; }); return tag_count; } } = self = .where(scope) if scope.present? results = .map_reduce(map, reduce).out(inline: true) results.to_a.map!{ |item| { :name => item['_id'], :count => item['value'].to_i } } end |
#scoped_tags(scope = {}) ⇒ Object
60 61 62 63 |
# File 'lib/mongoid-simple-tags.rb', line 60 def (scope = {}) warn "[DEPRECATION] `scoped_tags` is deprecated. Please use `all_tags` instead." (scope) end |
#tag_list ⇒ Object
75 76 77 |
# File 'lib/mongoid-simple-tags.rb', line 75 def tag_list self..collect{|tag| tag[:name]} end |
#tagged_with(tags) ⇒ Object
65 66 67 68 |
# File 'lib/mongoid-simple-tags.rb', line 65 def tagged_with() = [] unless .is_a? Array criteria.in(:tags => ) end |
#tagged_with_all(tags) ⇒ Object
70 71 72 73 |
# File 'lib/mongoid-simple-tags.rb', line 70 def tagged_with_all() = [] unless .is_a? Array criteria.all(:tags => ) end |