Skip to content

Instantly share code, notes, and snippets.

@ddeaguiar
Created September 9, 2013 14:44
Show Gist options
  • Save ddeaguiar/6496588 to your computer and use it in GitHub Desktop.
Save ddeaguiar/6496588 to your computer and use it in GitHub Desktop.
(ns noti.notify
(:require [noti.notification :as n]
[io.pedestal.service.log :as log]))
(defprotocol Notifiable
(notify! [_ x]))
(defmacro notifiable [body]
`(reify Notifiable
(notify! [_ notification]
(try
~body
(catch Exception e# (log/error :msg (.getMessage e#)))))))
(def log-notifier
(notifiable (spit "resources/public/notifications.txt"
(clojure.string/join "" [(n/text notification) "\n"])
:append true)))
@ddeaguiar
Copy link
Author

Although possible, I think it's best to avoid magic params like 'notification' in macro usage – line 17.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment