Skip to content

Commit

Permalink
Add :duct/regex reader tag
Browse files Browse the repository at this point in the history
  • Loading branch information
iku000888 committed Mar 29, 2019
1 parent c5fb68a commit dab4953
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/duct/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
[duct.core.resource :as resource]
[integrant.core :as ig]
[medley.core :as m]
[clojure.walk :as walk]))
[clojure.walk :as walk])
(:import [java.util.regex Pattern]))

(def target-path
"A path to place generated files in. Typically used by compilers. Can be set
Expand Down Expand Up @@ -110,7 +111,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 +121,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"}

0 comments on commit dab4953

Please sign in to comment.