-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.clj
38 lines (31 loc) · 1.24 KB
/
config.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
; This Source Code Form is subject to the terms of the Mozilla Public
; License, v. 2.0. If a copy of the MPL was not distributed with this
; file, You can obtain one at https://mozilla.org/MPL/2.0/.
(ns noahtheduke.splint.config
(:require
[clojure.edn :as edn]
[clojure.java.io :as io]))
(set! *warn-on-reflection* true)
(defn read-default-config []
(edn/read-string (slurp (io/resource "config/default.edn"))))
(def default-config
(delay (read-default-config)))
(defn find-local-config []
(loop [dir (.getParentFile (.getAbsoluteFile (io/file ".")))]
(let [config (io/file dir ".splint.edn")]
(if (.exists config)
(edn/read-string (slurp config))
(when-let [parent (.getParentFile dir)]
(recur parent))))))
(defn deep-merge [& maps]
(letfn [(reconcile-keys [val-in-result val-in-latter]
(if (and (map? val-in-result)
(map? val-in-latter))
(merge-with reconcile-keys val-in-result val-in-latter)
val-in-latter))
(reconcile-maps [result latter]
(merge-with reconcile-keys result latter))]
(reduce reconcile-maps {} maps)))
(defn load-config []
(let [local (find-local-config)]
(deep-merge @default-config local)))