Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/outpace/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,20 @@
"Finds and loads config."
[]
(if-let [source (find-config-source)]
(read-config source)
(with-meta (read-config source) :source source)
{}))

(def config
"The delayed map of explicit configuration values."
(delay (load-config)))

(defn config-source
"Returns the source of config as string or nil if no source was
found."
[]
(when-let [source (:source (meta @config))]
(str source)))

(defn present?
"Returns true if a configuration entry exists for the qname and, if an
Optional value, the value is provided."
Expand Down Expand Up @@ -272,7 +279,10 @@
(if (present? qname#)
(alter-var-root var# (constantly (lookup qname#)))
(when (and (-> var# meta :required) (not generating?))
(throw (Exception. (str "Missing required value for config var: " qname#)))))
(let [message# (if-let [source# (config-source)]
(str "Config var " qname# " must define a default or be specified in " source#)
(str "Config var " qname# " must define a default when there is no config source"))]
(throw (Exception. message#)))))
(when-let [validate# (and (bound? var#) (-> var# meta :validate))]
(validate @var# qname# validate#)))
var#))
Expand Down
3 changes: 2 additions & 1 deletion src/outpace/config/bootstrap.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
(io/resource res)
(or (System/getProperty "config.edn")
(when (.exists (io/file "config.edn"))
"config.edn")))))
"config.edn")))
(println "WARNING: no config source could be found.")))
6 changes: 6 additions & 0 deletions test/outpace/config_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,9 @@
(is (not (c/provided? #{(extractable "bar" false)})))
(is (not (c/provided? (list (extractable "bar" false)))))
(is (not (c/provided? [(extractable "bar" false)])))))

(deftest config-source-test
(let [source "config.clj"
config (delay (with-meta {} {:source source}))]
(with-redefs [c/config config]
(is (= source (c/config-source))))))