Last active
April 3, 2023 18:33
-
-
Save lazaronixon/fbde4ef1a9eebf995d7fae29b02b2599 to your computer and use it in GitHub Desktop.
Action deliver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Deliveries::AppointmentCancelationDelivery < Deliveries::Delivery | |
protected | |
def notification | |
AppointmentNotifier.canceled(recipient) | |
end | |
def mail | |
AppointmentMailer.canceled(deliverable, recipient) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Deliveries::Delivery | |
extend Suppressible | |
def initialize(deliverable, recipient) | |
@deliverable, @recipient = deliverable, recipient | |
end | |
def self.deliver(deliverable, recipient) | |
new(deliverable, recipient).deliver | |
end | |
def deliver | |
return if suppressed? | |
notification.try :notify_later | |
mail.try :deliver_later | |
end | |
private | |
attr_reader :deliverable, :recipient | |
def suppressed? | |
Deliveries::Delivery.suppressed? | |
end | |
def notification | |
# Must be implemented in concrete subclass | |
end | |
def mail | |
# Must be implemented in concrete subclass | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem "abstract_notifier" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Suppressible | |
def self.extended(base) | |
base.thread_mattr_accessor :suppressed, instance_accessor: false | |
base.delegate :suppressed?, to: "self.class" | |
end | |
def suppress(&block) | |
original, self.suppressed = self.suppressed, true | |
yield | |
ensure | |
self.suppressed = original | |
end | |
def suppressed? | |
suppressed | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment