Skip to content

Commit

Permalink
Add annotate and describe functions
Browse files Browse the repository at this point in the history
  • Loading branch information
weavejester committed Sep 29, 2024
1 parent 8dab89b commit 06dfa79
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/integrant/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@
[clojure.string :as str]
[weavejester.dependency :as dep]))

(def ^:private registry (atom {}))

(defn annotate
"Annotate a namespaced keyword with a map of metadata that will be stored in a
global registry. Use [[describe]] to retrieve the keyword annotation map."
[kw metadata]
{:pre [(qualified-keyword? kw) (map? metadata)]}
(swap! registry assoc kw metadata))

(defn describe
"Return the annotation map for a namespaced keyword."
[kw]
{:pre [(qualified-keyword? kw)]}
(@registry kw))

(defprotocol RefLike
(ref-key [r] "Return the key of the reference.")
(ref-resolve [r config resolvef] "Return the resolved value."))
Expand Down
6 changes: 6 additions & 0 deletions test/integrant/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
(defn- init-example [v]
(str "init" v))

(deftest annotate-describe-test
(ig/annotate ::foo {:doc "A test keyword"})
(ig/annotate ::bar {:doc "Another test keyword"})
(is (= {:doc "A test keyword"} (ig/describe ::foo)))
(is (= {:doc "Another test keyword"} (ig/describe ::bar))))

(deftest ref-test
(is (ig/ref? (ig/ref ::foo)))
(is (ig/ref? (ig/ref [::foo ::bar])))
Expand Down

0 comments on commit 06dfa79

Please sign in to comment.