Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add :duct/regex reader tag #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/duct/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@
(merge
{'duct/env env/env
'duct/include (make-include readers)
'duct/resource resource}
'duct/resource resource
'duct/regex re-pattern}
readers))

(defn read-config
Expand All @@ -119,7 +120,7 @@

#duct/env
: an environment variable, see [[duct.core.env/env]]

#duct/include
: substitute for a configuration on the classpath

Expand Down
15 changes: 9 additions & 6 deletions test/duct/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@
{::a {:x 1}} {::a (ig/refset ::b)} {::a (ig/refset ::b)}))

(deftest test-read-config
(is (= (core/read-config (io/resource "duct/readers.edn") {'custom/bar (fn [x] {:x x})})
{:foo/a {:x "bar"}
:foo/b {:bar/a {:x 1}, :bar/b (ig/ref :bar/a) :bar/c {:baz/a {:x 1}}}
:foo/c (core/resource "duct/config.edn")
:foo/d (ig/ref :foo/a)
:foo/e (ig/refset :foo/b)})))
(let [config (core/read-config (io/resource "duct/readers.edn") {'custom/bar (fn [x] {:x x})})]
(is (= (dissoc config :foo/f)
{:foo/a {:x "bar"}
:foo/b {:bar/a {:x 1}, :bar/b (ig/ref :bar/a) :bar/c {:baz/a {:x 1}}}
:foo/c (core/resource "duct/config.edn")
:foo/d (ig/ref :foo/a)
:foo/e (ig/refset :foo/b)}))
(is (= (.pattern (:foo/f config))
"baz"))))

(defmethod ig/init-key ::foo [_ {:keys [x]}]
#(update % ::x (fnil conj []) x))
Expand Down
3 changes: 2 additions & 1 deletion test/duct/readers.edn
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
:foo/b #duct/include "duct/config.edn"
:foo/c #duct/resource "duct/config.edn"
:foo/d #ig/ref :foo/a
:foo/e #ig/refset :foo/b}
:foo/e #ig/refset :foo/b
:foo/f #duct/regex "baz"}