Module: Mongoid::Document::Taggable::ClassMethods
- Defined in:
- lib/workarea/ext/freedom_patches/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
- #tagged_without(tags) ⇒ Object
Instance Method Details
#all_tags(scope = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/workarea/ext/freedom_patches/mongoid_simple_tags.rb', line 61 def (scope = {}) map = %{ function() { if(this.tags){ this.tags.forEach(function(tag){ emit(tag, 1) }); } } } reduce = %{ 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: 1) results.to_a.map! { |item| { name: item['_id'], count: item['value'].to_i } } end |
#scoped_tags(scope = {}) ⇒ Object
37 38 39 40 |
# File 'lib/workarea/ext/freedom_patches/mongoid_simple_tags.rb', line 37 def (scope = {}) warn "[DEPRECATION] `scoped_tags` is deprecated. Please use `all_tags` instead." (scope) end |
#tag_list ⇒ Object
57 58 59 |
# File 'lib/workarea/ext/freedom_patches/mongoid_simple_tags.rb', line 57 def tag_list self..collect { |tag| tag[:name] } end |
#tagged_with(tags) ⇒ Object
42 43 44 45 |
# File 'lib/workarea/ext/freedom_patches/mongoid_simple_tags.rb', line 42 def tagged_with() = [] unless .is_a? Array criteria.in(tags: ) end |
#tagged_with_all(tags) ⇒ Object
52 53 54 55 |
# File 'lib/workarea/ext/freedom_patches/mongoid_simple_tags.rb', line 52 def tagged_with_all() = [] unless .is_a? Array criteria.all(tags: ) end |
#tagged_without(tags) ⇒ Object
47 48 49 50 |
# File 'lib/workarea/ext/freedom_patches/mongoid_simple_tags.rb', line 47 def tagged_without() = [] unless .is_a? Array criteria.nin(tags: ) end |