Created
October 10, 2017 04:05
-
-
Save kklimuk/63ff6b6e57fc01d5ab8761d1b0afe191 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 Notifier | |
attr_reader :notifier | |
def initialize(notifier) | |
raise ArgumentError, 'Expected the notifier to respond to `notify`' unless notifier.respond_to?(:notify) | |
@notifier = notifier | |
end | |
def notify(id, message) | |
notifier.notify(id, prettify(message)) | |
end | |
def prettify(message) | |
HTMLCleaner.clean(message.strip) | |
end | |
end | |
class Mailer < DefaultMailer | |
def notify(email, message) | |
mail(to: email) { render :plain, message } | |
end | |
end | |
Notifier.new(Mailer.new).notify('[email protected]', 'hey there') | |
Notifier.new(SlackClient.new).notify('@kirill', 'hello, <strong>world</strong>') | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment