From c43252253c251c1a5309eee2e683628678bb6565 Mon Sep 17 00:00:00 2001 From: Ricky Gu Date: Sun, 15 Oct 2017 22:30:35 -0700 Subject: [PATCH 1/2] add friendship_status method --- lib/has_friendship/friendable.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/has_friendship/friendable.rb b/lib/has_friendship/friendable.rb index bc0035f..f83a89a 100644 --- a/lib/has_friendship/friendable.rb +++ b/lib/has_friendship/friendable.rb @@ -87,6 +87,11 @@ def on_relation_with(friend) def friends_with?(friend) HasFriendship::Friendship.find_relation(self, friend, status: 2).any? end + + def friendship_status(friend) + friendship = HasFriendship::Friendship.find_relation(self, friend) + friendship.first.status if friendship.any? + end def on_friendship_created(*args); end def on_friendship_accepted(*args); end From 9f2b605876e1b818127625d489e30b819a2ab563 Mon Sep 17 00:00:00 2001 From: Ricky Gu Date: Sun, 15 Oct 2017 22:31:54 -0700 Subject: [PATCH 2/2] add friendship_status readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 7b67a09..9dc1d26 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,10 @@ remove friendship to the one that initially blocked it. ```ruby # Check if there is an accepted friendship between @mac and @dee @mac.friends_with?(@dee) + +# Check the status between two friends +@mac.friendship_status(@dee) # => "pending" + ``` ### Type of friends