Last active
March 7, 2019 14:15
-
-
Save pcasaretto/2c147d5a52b5c41f7d69a3fd6473b038 to your computer and use it in GitHub Desktop.
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 BaseUserMailer | |
def initialize(smtp_settings) | |
@client = MailSendingLibrary.new(smtp_settings) | |
end | |
def send_mail(user,mail) | |
@client.send_mail(user.email, mail.body) | |
end | |
end | |
class TransactionalMailer | |
SMTP_SETTINGS = ... | |
def initialize() | |
@mailer = BaseUserMailer.new(SMTP_SETTINGS) | |
end | |
def send_mail(user,mail) | |
@mailer.send_mail(user.email, mail.body) | |
end | |
end | |
class MarketingMailer | |
SMTP_SETTINGS = ... | |
def initialize() | |
@mailer = BaseUserMailer.new(SMTP_SETTINGS) | |
end | |
def send_mail(user,mail) | |
@mailer.send_mail(user.email, mail.body) | |
end | |
end | |
class LoggingMailer | |
def initialize(mailer) | |
@mailer = mailer | |
end | |
def send_mail(user,mail) | |
p "sending email to user #{user.id}" | |
@mailer.send_mail(user.email, mail.body) | |
end | |
end | |
class BlockingMailer | |
def initialize(mailer) | |
@mailer = mailer | |
end | |
def send_mail(user,mail) | |
return unless @user.has_active_subscription? | |
@mailer.send_mail(user.email, mail.body) | |
end | |
end | |
# using the code would be something like: | |
mailer = BlockingMailer.new(LoggingMailer.new(TransactionalMailer.new())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment