Skip to content

Commit

Permalink
refatora NotificationStrategy
Browse files Browse the repository at this point in the history
  • Loading branch information
hreis1 committed Feb 16, 2024
1 parent 5dd5b91 commit 984bdb0
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions app/models/notification_strategy.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
class NotificationStrategy < SimpleDelegator
STRATEGY = {
Invitation => ->(notifiable) { notifiable },
Post => ->(notifiable) { notifiable },
Comment => ->(notifiable) { notifiable.post },
Connection => ->(notifiable) { notifiable.follower },
Like => ->(notifiable) { notifiable.likeable.is_a?(Comment) ? notifiable.likeable.post : notifiable.likeable }
}.freeze

def redirect_after_click
STRATEGY[notifiable.class].call(notifiable)
case notifiable
when Comment
notifiable.post
when Connection
notifiable.follower
when Like
notifiable.likeable.is_a?(Comment) ? notifiable.likeable.post : notifiable.likeable
else
notifiable
end
end
end

0 comments on commit 984bdb0

Please sign in to comment.