Files
fizzy/app/models/notifier.rb
T
Jorge Manrubia 8aa99e34b4 Persist notification's creator
Instead of delegating. With a polymorphic relationship, relying on a certain
attribute implies doing things like aliasing "mentioner" to "creator" or similar.
2025-04-22 13:48:43 +02:00

36 lines
634 B
Ruby

class Notifier
attr_reader :source
class << self
def for(source)
case source
when Event
"Notifier::Events::#{source.action.classify}".safe_constantize&.new(source)
when ::Mention
Notifier::Mention.new(source)
end
end
end
def notify
if should_notify?
recipients.map do |recipient|
Notification.create! user: recipient, source: source, resource: resource, creator: creator
end
end
end
private
def initialize(source)
@source = source
end
def should_notify?
true
end
def resource
source
end
end