Skip to content

Commit 06dfa79

Browse files
committed
Add annotate and describe functions
1 parent 8dab89b commit 06dfa79

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/integrant/core.cljc

+15
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@
77
[clojure.string :as str]
88
[weavejester.dependency :as dep]))
99

10+
(def ^:private registry (atom {}))
11+
12+
(defn annotate
13+
"Annotate a namespaced keyword with a map of metadata that will be stored in a
14+
global registry. Use [[describe]] to retrieve the keyword annotation map."
15+
[kw metadata]
16+
{:pre [(qualified-keyword? kw) (map? metadata)]}
17+
(swap! registry assoc kw metadata))
18+
19+
(defn describe
20+
"Return the annotation map for a namespaced keyword."
21+
[kw]
22+
{:pre [(qualified-keyword? kw)]}
23+
(@registry kw))
24+
1025
(defprotocol RefLike
1126
(ref-key [r] "Return the key of the reference.")
1227
(ref-resolve [r config resolvef] "Return the resolved value."))

test/integrant/core_test.cljc

+6
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@
7373
(defn- init-example [v]
7474
(str "init" v))
7575

76+
(deftest annotate-describe-test
77+
(ig/annotate ::foo {:doc "A test keyword"})
78+
(ig/annotate ::bar {:doc "Another test keyword"})
79+
(is (= {:doc "A test keyword"} (ig/describe ::foo)))
80+
(is (= {:doc "Another test keyword"} (ig/describe ::bar))))
81+
7682
(deftest ref-test
7783
(is (ig/ref? (ig/ref ::foo)))
7884
(is (ig/ref? (ig/ref [::foo ::bar])))

0 commit comments

Comments
 (0)