Last active
January 1, 2016 15:59
-
-
Save bbbates/8167593 to your computer and use it in GitHub Desktop.
Merging simple map-based environment configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def base-config | |
{ | |
:value "some value" | |
}) | |
(defn- merge-cfg-item | |
[base-item override-item] | |
(cond | |
(and (every? map? [base-item override-item]) (not (contains? override-item :replace-all!))) | |
(merge-with merge-cfg-item base-item override-item) | |
(and (every? map? [base-item override-item]) (contains? override-item :replace-all!)) | |
(dissoc override-item :replace-all!) | |
:else override-item)) | |
(defn merge-cfg | |
[base-cfg override-cfg] | |
(merge-with merge-cfg-item base-cfg override-cfg)) | |
(def ^{:private true} region-config | |
(if-let [region (System/getProperty "region")] | |
(merge-cfg base-config | |
(read-string (slurp (io/input-stream (io/resource (apply str "conf/" region)))))) | |
base-config)) | |
(defn get-cfg | |
[& kws] | |
(get-in region-config ks)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment