Module: Mongo::Likeable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/mongo_likeable/mongo_likeable.rb
Instance Method Summary collapse
- #all_dislikers ⇒ Object
- #all_likers ⇒ Object
- #clear_dislikes(*models) ⇒ Object
- #clear_likes(*models) ⇒ Object
- #dislike(*models) ⇒ Object
- #dislike?(model) ⇒ Boolean
- #dislike_counts ⇒ Object
- #dislike_history ⇒ Object
- #like(*models) ⇒ Object
- #like?(model) ⇒ Boolean
- #like_counts ⇒ Object
- #like_history ⇒ Object
Instance Method Details
#all_dislikers ⇒ Object
65 66 67 |
# File 'lib/mongo_likeable/mongo_likeable.rb', line 65 def all_dislikers rebuild_instance(*self.dislikers) end |
#all_likers ⇒ Object
61 62 63 |
# File 'lib/mongo_likeable/mongo_likeable.rb', line 61 def all_likers rebuild_instance(*self.likers) end |
#clear_dislikes(*models) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/mongo_likeable/mongo_likeable.rb', line 101 def clear_dislikes(*models) if models == [] self.dislikes = [] else self.dislikes -= simplify_instance(*models) models.each do |model| model.likers -= simplify_instance(self) model.save end end self.save end |
#clear_likes(*models) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/mongo_likeable/mongo_likeable.rb', line 85 def clear_likes(*models) if models == [] self.likes = [] else self.likes -= simplify_instance(*models) models.each do |model| model.likers -= simplify_instance(self) model.save end end self.save end |
#dislike(*models) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mongo_likeable/mongo_likeable.rb', line 40 def dislike(*models) self.dislikes |= simplify_instance(*models) self.dislike_histories |= simplify_instance(*models) models.each do |model| model.likers |= simplify_instance(self) model.save end self.save end |
#dislike?(model) ⇒ Boolean
81 82 83 |
# File 'lib/mongo_likeable/mongo_likeable.rb', line 81 def dislike?(model) self.dislikes.include? simplify_instance(model)[0] end |
#dislike_counts ⇒ Object
57 58 59 |
# File 'lib/mongo_likeable/mongo_likeable.rb', line 57 def dislike_counts self.dislikes.length end |
#dislike_history ⇒ Object
73 74 75 |
# File 'lib/mongo_likeable/mongo_likeable.rb', line 73 def dislike_history rebuild_instance(*self.dislike_histories) end |
#like(*models) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mongo_likeable/mongo_likeable.rb', line 27 def like(*models) self.likes |= simplify_instance(*models) self.like_histories |= simplify_instance(*models) models.each do |model| model.likers |= simplify_instance(self) model.save end self.save end |
#like?(model) ⇒ Boolean
77 78 79 |
# File 'lib/mongo_likeable/mongo_likeable.rb', line 77 def like?(model) self.likes.include? simplify_instance(model)[0] end |
#like_counts ⇒ Object
53 54 55 |
# File 'lib/mongo_likeable/mongo_likeable.rb', line 53 def like_counts self.likes.length end |
#like_history ⇒ Object
69 70 71 |
# File 'lib/mongo_likeable/mongo_likeable.rb', line 69 def like_history rebuild_instance(*self.like_histories) end |