Skip to content

Commit

Permalink
Merge pull request #19 from hden/get-params
Browse files Browse the repository at this point in the history
allow default values in get-params
  • Loading branch information
hden committed Apr 12, 2021
2 parents 171334b + 29e20fc commit 64b506b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject hden/duct.module.datomic "0.4.1"
(defproject hden/duct.module.datomic "0.5.0"
:description "A Duct module that adds Integrant keys for a Datomic database connection and Ragtime migrations to a configuration."
:url "https://github.com/hden/duct.module.datomic"
:license {:name "EPL-2.0"
Expand Down
19 changes: 11 additions & 8 deletions src/duct/reader/ion.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
[uritemplate-clj.core :as templ]))

(def get-params
(memoize (fn
([s] (get-params s {}))
([s m]
(let [vars {:app-name (get (ion/get-app-info) :app-name)
:env (get (ion/get-env) :env)}]
(ion/get-params {:path (templ/uritemplate s (merge vars m))}))))))
(memoize (fn [{:keys [template variables default]
:or {variables {}
default {}}}]
(let [vars {:app-name (get (ion/get-app-info) :app-name)
:env (get (ion/get-env) :env)}
params (ion/get-params {:path (templ/uritemplate template (merge vars variables))})]
(if (= {} params)
default
params)))))

(defmethod ig/init-key ::get-params [_ {:keys [template variables]}]
(get-params template (or variables {})))
(defmethod ig/init-key ::get-params [_ opts]
(get-params opts))

0 comments on commit 64b506b

Please sign in to comment.