Module: Mongoid::Taggable::ClassMethods
- Defined in:
- lib/mongoid/taggable.rb
Instance Method Summary collapse
- #disable_tags_index! ⇒ Object
- #enable_tags_index! ⇒ Object
- #save_tags_index! ⇒ Object
-
#tags ⇒ Object
get an array with all defined tags for this model, this list returns an array of distinct ordered list of tags defined in all documents of this model.
- #tags_index_collection ⇒ Object
- #tags_separator(separator = nil) ⇒ Object
-
#tags_with_weight ⇒ Object
retrieve the list of tags with weight(count), this is usefull for creating tag clouds.
Instance Method Details
#disable_tags_index! ⇒ Object
50 51 52 |
# File 'lib/mongoid/taggable.rb', line 50 def @do_tags_index = false end |
#enable_tags_index! ⇒ Object
54 55 56 |
# File 'lib/mongoid/taggable.rb', line 54 def @do_tags_index = true end |
#save_tags_index! ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/mongoid/taggable.rb', line 67 def return unless @do_tags_index db = Mongoid::Config.master coll = db.collection(collection_name) map = "function() { if (!this.tags_array) { return; } for (index in this.tags_array) { emit(this.tags_array[index], 1); } }" reduce = "function(previous, current) { var count = 0; for (index in current) { count += current[index] } return count; }" coll.map_reduce(map, reduce, :out => ) end |
#tags ⇒ Object
get an array with all defined tags for this model, this list returns an array of distinct ordered list of tags defined in all documents of this model
38 39 40 41 |
# File 'lib/mongoid/taggable.rb', line 38 def db = Mongoid::Config.master db.collection().find.to_a.map{ |r| r["_id"] } end |
#tags_index_collection ⇒ Object
63 64 65 |
# File 'lib/mongoid/taggable.rb', line 63 def "#{collection_name}_tags_index" end |
#tags_separator(separator = nil) ⇒ Object
58 59 60 61 |
# File 'lib/mongoid/taggable.rb', line 58 def (separator = nil) @tags_separator = separator if separator @tags_separator || ',' end |
#tags_with_weight ⇒ Object
retrieve the list of tags with weight(count), this is usefull for creating tag clouds
45 46 47 48 |
# File 'lib/mongoid/taggable.rb', line 45 def db = Mongoid::Config.master db.collection().find.to_a.map{ |r| [r["_id"], r["value"]] } end |