Last active
December 13, 2015 17:28
-
-
Save gtrak/4948166 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
;;; helpful to get rid of repetitive compojure destructuring. | |
(defmacro wrap-request-binding | |
"Wraps the ring handler definition to provide request-scoped bindings | |
via symbol-capture on %." | |
[bindings handler-def] | |
`(fn [request#] | |
(let [~'% request# | |
~@bindings] | |
(~handler-def req#)))) | |
(defmacro binding-handlers | |
"Request-scoped bindings on multiple handlers. Expands to a sequence of | |
handlers (use routes instead of defroutes)." | |
[bindings & handlers] | |
(mapv (fn [handler] `(wrap-request-binding ~bindings ~handler)) handlers)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment