Skip to content

Instantly share code, notes, and snippets.

@kklimuk
Created October 10, 2017 04:05
Show Gist options
  • Save kklimuk/63ff6b6e57fc01d5ab8761d1b0afe191 to your computer and use it in GitHub Desktop.
Save kklimuk/63ff6b6e57fc01d5ab8761d1b0afe191 to your computer and use it in GitHub Desktop.
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