Module: Has::Followers::InstanceMethods
- Defined in:
- lib/has_followers/has_followers.rb
Instance Method Summary collapse
- #follow(followed) ⇒ Object
- #follow_me?(follower) ⇒ Boolean
- #followed_for(follower) ⇒ Object
- #following?(followed) ⇒ Boolean
- #following_for(followed) ⇒ Object
- #is?(followed) ⇒ Boolean
- #unfollow(followed) ⇒ Object
Instance Method Details
#follow(followed) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/has_followers/has_followers.rb', line 19 def follow(followed) unless following?(followed) || is?(followed) ActiveRecord::Base.transaction do Follow.create(:user_id => self.id, :followed_id => followed.id) increment_counters(followed) end end end |
#follow_me?(follower) ⇒ Boolean
48 49 50 |
# File 'lib/has_followers/has_followers.rb', line 48 def follow_me?(follower) return follow = followed_for(follower) end |
#followed_for(follower) ⇒ Object
52 53 54 |
# File 'lib/has_followers/has_followers.rb', line 52 def followed_for(follower) self.followers.where( :id => follower.id ).first end |
#following?(followed) ⇒ Boolean
40 41 42 |
# File 'lib/has_followers/has_followers.rb', line 40 def following?(followed) return follow = following_for(followed) end |
#following_for(followed) ⇒ Object
44 45 46 |
# File 'lib/has_followers/has_followers.rb', line 44 def following_for(followed) self.followeds.where( :id => followed.id ).first end |
#is?(followed) ⇒ Boolean
56 57 58 |
# File 'lib/has_followers/has_followers.rb', line 56 def is?(followed) self.id.eql?( followed.id ) end |
#unfollow(followed) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/has_followers/has_followers.rb', line 28 def unfollow(followed) if following?(followed) && ! is?(followed) ActiveRecord::Base.transaction do follow = following_for(followed) unless follow.nil? follow.destroy decrement_counters(followed) end end end end |