Welcome Interceptor registry!

This commit is contained in:
Tommi Reiman 2018-07-27 15:14:10 +03:00
parent 94431352b8
commit 6c47b5fa94
2 changed files with 24 additions and 0 deletions

View file

@ -13,6 +13,17 @@
(extend-protocol IntoInterceptor
#?(:clj clojure.lang.Keyword
:cljs cljs.core.Keyword)
(into-interceptor [this data {:keys [::registry] :as opts}]
(or (if-let [interceptor (if registry (registry this))]
(into-interceptor interceptor data opts))
(throw
(ex-info
(str "Interceptor " (pr-str this) " not found in registry.")
{:keyword this
:registry registry}))))
#?(:clj clojure.lang.APersistentVector
:cljs cljs.core.PersistentVector)
(into-interceptor [[f & args :as form] data opts]

View file

@ -58,6 +58,19 @@
(is (= [:value :ok] (app ctx)))
(is (= 1 @calls)))))
(testing "as keyword"
(reset! calls 0)
(let [app (create [:enter] {::interceptor/registry {:enter (enter :value)}})]
(dotimes [_ 10]
(is (= [:value :ok] (app ctx)))
(is (= 1 @calls)))))
(testing "missing keyword"
(is (thrown-with-msg?
ExceptionInfo
#"Interceptor :enter not found in registry"
(create [:enter]))))
(testing "as map"
(reset! calls 0)
(let [app (create [{:enter (enter :value)}])]