Skip to content

Instantly share code, notes, and snippets.

@emidln
Created September 25, 2015 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emidln/b45d2dbf2fbf5ea8afe1 to your computer and use it in GitHub Desktop.
Save emidln/b45d2dbf2fbf5ea8afe1 to your computer and use it in GitHub Desktop.
(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