module HasFriendship::Friendable::InstanceMethods
Constants
- CALLBACK_METHOD_NAMES
Public Instance Methods
accept_request(friend)
click to toggle source
# File lib/has_friendship/friendable.rb, line 63 def accept_request(friend) on_relation_with(friend) do |one, other| friendship = HasFriendship::Friendship.find_unblocked_friendship(one, other) friendship.accept! if can_accept_request?(friendship) end end
block_friend(friend)
click to toggle source
# File lib/has_friendship/friendable.rb, line 78 def block_friend(friend) on_relation_with(friend) do |one, other| HasFriendship::Friendship.find_unblocked_friendship(one, other).block! end end
decline_request(friend)
click to toggle source
# File lib/has_friendship/friendable.rb, line 70 def decline_request(friend) on_relation_with(friend) do |one, other| HasFriendship::Friendship.find_unblocked_friendship(one, other).destroy end end
Also aliased as: remove_friend
friend_request(friend)
click to toggle source
# File lib/has_friendship/friendable.rb, line 54 def friend_request(friend) unless self == friend || HasFriendship::Friendship.exist?(self, friend) transaction do HasFriendship::Friendship.create_relation(self, friend, status: 0) HasFriendship::Friendship.create_relation(friend, self, status: 1) end end end
friends_with?(friend)
click to toggle source
# File lib/has_friendship/friendable.rb, line 98 def friends_with?(friend) HasFriendship::Friendship.find_relation(self, friend, status: 2).any? end
on_relation_with(friend) { |self, friend| ... }
click to toggle source
# File lib/has_friendship/friendable.rb, line 91 def on_relation_with(friend) transaction do yield(self, friend) yield(friend, self) end end
unblock_friend(friend)
click to toggle source
# File lib/has_friendship/friendable.rb, line 84 def unblock_friend(friend) return unless has_blocked(friend) on_relation_with(friend) do |one, other| HasFriendship::Friendship.find_blocked_friendship(one, other).destroy end end
Private Instance Methods
can_accept_request?(friendship)
click to toggle source
# File lib/has_friendship/friendable.rb, line 108 def can_accept_request?(friendship) return if friendship.pending? && self == friendship.friendable return if friendship.requested? && self == friendship.friend true end
has_blocked(friend)
click to toggle source
# File lib/has_friendship/friendable.rb, line 104 def has_blocked(friend) HasFriendship::Friendship.find_one_side(self, friend).blocker_id == self.id end