Skip to content

Instantly share code, notes, and snippets.

@lazaronixon
Last active February 18, 2026 19:56
Show Gist options
  • Select an option

  • Save lazaronixon/a3fe1ac7d608506c15b8c57d06de7d7f to your computer and use it in GitHub Desktop.

Select an option

Save lazaronixon/a3fe1ac7d608506c15b8c57d06de7d7f to your computer and use it in GitHub Desktop.
Notification
# app/models/deliveries/appointment_cancelation_delivery.rb
class Deliveries::AppointmentCancelationDelivery < Deliveries::Delivery
protected
def notification
AppointmentNotifier.canceled(recipient)
end
def mail
AppointmentMailer.canceled(deliverable, recipient)
end
end
# app/notifiers/appointment_notifier.rb
# https://github.com/palkan/abstract_notifier
class AppointmentNotifier < ApplicationNotifier
def assigned(recipient)
notification identity: recipient.identity, body: "New appointment assigned 🎉"
end
def reminder(recipient)
notification identity: recipient.identity, body: "Your appointment is about to start ⚡️"
end
def rescheduled(recipient)
notification identity: recipient.identity, body: "Your appointment was rescheduled 🚨"
end
def canceled(recipient)
notification identity: recipient.identity, body: "Your appointment has been cancelled ☹️"
end
end
# app/models/appointment/cancelation.rb
class Appointment::Cancelation < ApplicationRecord
encrypts :subject
belongs_to :patient, class_name: "User"
after_create_commit do
Deliveries::AppointmentCancelationDelivery.deliver(self, patient)
end
def self.cancel(appointment)
create! subject: appointment.subject, starts_at: appointment.starts_at, patient: appointment.patient
end
end
# app/models/deliveries/delivery.rb
class Deliveries::Delivery
def initialize(deliverable, recipient)
@deliverable, @recipient = deliverable, recipient
end
def self.deliver(deliverable, recipient)
new(deliverable, recipient).deliver
end
def deliver
notification.try :notify_later
mail.try :deliver_later
end
private
attr_reader :deliverable, :recipient
def notification
# Must be implemented in concrete subclass
end
def mail
# Must be implemented in concrete subclass
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment