From da561137d944d0e351c02fb95186067f719fbbfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Siwek?= Date: Sat, 2 Jun 2018 18:04:37 +0200 Subject: [PATCH] Create .on_friendship_destroyed callback --- README.md | 4 ++++ lib/has_friendship/friendable.rb | 1 + lib/has_friendship/friendship.rb | 8 ++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7b67a09..419c48d 100644 --- a/README.md +++ b/README.md @@ -165,6 +165,10 @@ end def on_friendship_blocked(friendship) ... end + +def on_friendship_destroyed(friendship) + ... +end ``` ## Roadmap diff --git a/lib/has_friendship/friendable.rb b/lib/has_friendship/friendable.rb index 3492a29..10a1a19 100644 --- a/lib/has_friendship/friendable.rb +++ b/lib/has_friendship/friendable.rb @@ -42,6 +42,7 @@ module InstanceMethods on_friendship_created on_friendship_accepted on_friendship_blocked + on_friendship_destroyed ).freeze CALLBACK_METHOD_NAMES.each do |method_name| diff --git a/lib/has_friendship/friendship.rb b/lib/has_friendship/friendship.rb index 2f717b5..e99179f 100644 --- a/lib/has_friendship/friendship.rb +++ b/lib/has_friendship/friendship.rb @@ -1,8 +1,12 @@ module HasFriendship class Friendship < ActiveRecord::Base - after_create do - friend.on_friendship_created(self) + after_create do |record| + record.friend.on_friendship_created(record) + end + + after_destroy do |record| + record.friend.on_friendship_destroyed(record) end enum status: { pending: 0, requested: 1, accepted: 2, blocked: 3 } do