Class: Friendship
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Friendship
- Defined in:
- app/models/friendship.rb
Constant Summary collapse
- @@daily_request_limit =
12
Class Method Summary collapse
Instance Method Summary collapse
- #accepted? ⇒ Boolean
- #cannot_request_if_daily_limit_reached ⇒ Object
- #denied? ⇒ Boolean
- #notify_requester ⇒ Object
- #pending? ⇒ Boolean
- #reverse ⇒ Object
Class Method Details
.friends?(user, friend) ⇒ Boolean
50 51 52 |
# File 'app/models/friendship.rb', line 50 def self.friends?(user, friend) where("user_id = ? AND friend_id = ? AND friendship_status_id = ?", user.id, friend.id, FriendshipStatus[:accepted].id).first end |
Instance Method Details
#accepted? ⇒ Boolean
46 47 48 |
# File 'app/models/friendship.rb', line 46 def accepted? friendship_status.eql?(FriendshipStatus[:accepted]) end |
#cannot_request_if_daily_limit_reached ⇒ Object
25 26 27 28 29 |
# File 'app/models/friendship.rb', line 25 def cannot_request_if_daily_limit_reached if new_record? && initiator && user.has_reached_daily_friend_request_limit? errors.add(:base, "Sorry, you'll have to wait a little while before requesting any more friendships.") end end |
#denied? ⇒ Boolean
38 39 40 |
# File 'app/models/friendship.rb', line 38 def denied? friendship_status.eql?(FriendshipStatus[:denied]) end |
#notify_requester ⇒ Object
54 55 56 |
# File 'app/models/friendship.rb', line 54 def notify_requester UserNotifier.friendship_accepted(self).deliver end |
#pending? ⇒ Boolean
42 43 44 |
# File 'app/models/friendship.rb', line 42 def pending? friendship_status.eql?(FriendshipStatus[:pending]) end |
#reverse ⇒ Object
34 35 36 |
# File 'app/models/friendship.rb', line 34 def reverse Friendship.where('user_id = ? and friend_id = ?', self.friend_id, self.user_id).first end |