Skip to content

Instantly share code, notes, and snippets.

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