Class: Friendship

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/friendship.rb

Constant Summary collapse

@@daily_request_limit =
12

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.friends?(user, friend) ⇒ Boolean

Returns:

  • (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

Returns:

  • (Boolean)


46
47
48
# File 'app/models/friendship.rb', line 46

def accepted?
  friendship_status.eql?(FriendshipStatus[:accepted])    
end

#cannot_request_if_daily_limit_reachedObject



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

Returns:

  • (Boolean)


38
39
40
# File 'app/models/friendship.rb', line 38

def denied?
  friendship_status.eql?(FriendshipStatus[:denied])
end

#notify_requesterObject



54
55
56
# File 'app/models/friendship.rb', line 54

def notify_requester
  UserNotifier.friendship_accepted(self).deliver
end

#pending?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/friendship.rb', line 42

def pending?
  friendship_status.eql?(FriendshipStatus[:pending])
end

#reverseObject



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