Skip to content

Commit

Permalink
implement unamespaced map function
Browse files Browse the repository at this point in the history
  • Loading branch information
macielti committed Jul 25, 2024
1 parent 30fc2d0 commit 2a32987
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/components/cronjob.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ After that you need to add the cronjob component to your system map:
(def system
(component/system-map
:cronjob (component.cronjob/new-cronjob <<tasks>>)))
```
```
12 changes: 12 additions & 0 deletions src/common_clj/misc/core.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(ns common-clj.misc.core
(:require [common-clj.keyword.core :as common-keyword]
[schema.core :as s]
[clojure.walk :refer [postwalk]]))

(s/defn un-namespaced :- (s/pred map?)
"Recursively un-namespace map keys"
[schema :- (s/pred map?)]
(postwalk (fn [x]
(if (keyword? x)
(common-keyword/un-namespaced x)
x)) schema))
15 changes: 15 additions & 0 deletions test/unit/common_clj/misc/core_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(ns common-clj.misc.core-test
(:require [clojure.test :refer :all]
[common-clj.misc.core :as misc]
[schema.test :as s]))

(s/deftest un-namespaced-test
(testing "Given a map with namespaced keys, it should return a map with un-namespaced keys"
(is (= {:a 1 :b 2}
(misc/un-namespaced {:test/a 1 :test/b 2})))

(is (= {:a 1 :b :key}
(misc/un-namespaced {:test/a 1 :test/b :namespaced/key})))

(is (= {:a 1 :b [:first :second]}
(misc/un-namespaced {:test/a 1 :test/b [:namespaced/first :namespaced/second]})))))

0 comments on commit 2a32987

Please sign in to comment.