Skip to content

Commit

Permalink
Create .on_friendship_destroyed callback
Browse files Browse the repository at this point in the history
  • Loading branch information
skycocker committed Jun 2, 2018
1 parent 85e9c0b commit da56113
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ end
def on_friendship_blocked(friendship)
...
end

def on_friendship_destroyed(friendship)
...
end
```

## Roadmap
Expand Down
1 change: 1 addition & 0 deletions lib/has_friendship/friendable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
8 changes: 6 additions & 2 deletions lib/has_friendship/friendship.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit da56113

Please sign in to comment.