Created
September 25, 2015 14:57
-
-
Save emidln/b45d2dbf2fbf5ea8afe1 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
(defrecord RingHandler | |
[handler injections app] | |
component/Lifecycle | |
(start [this] | |
(if app | |
this | |
(let [app (fn [req] | |
(let [injectables (select-keys this injections)] | |
(handler | |
(if (empty? injectables) | |
req | |
(apply assoc req (apply concat injectables))))))] | |
(assoc this :app app)))) | |
(stop [this] | |
(if this | |
(dissoc this :app) | |
this))) | |
(defn new-ring-handler | |
([handler] | |
(new-ring-handler handler nil)) | |
([handler injections] | |
(map->RingHandler {:handler http | |
:injections injections}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment