-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.clj
63 lines (51 loc) · 1.08 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
(ns cellar.config
(:refer-clojure :exclude [reset!]))
(declare ^:dynamic ^:private *config*)
(defn- -default
[]
{:tables {}
:db-settings {}})
(defn <get-
"Returns config"
[]
*config*)
(defn -set>
"Sets config"
[new-config]
(alter-var-root #'*config* (fn [_old] new-config)))
(defn reset!
"Resets config to default state"
[]
(-set> (-default)))
(defn <table-
"Returns `table` config if exists"
[table]
(get-in *config* [:tables table]))
(defn -table>
"Adds table `new-table` to config"
[new-table]
(->> new-table
(merge (:tables *config*))
(assoc *config* :tables)
(-set>)))
(defn <tables-
"Returns all tables configs"
[]
(:tables *config*))
(defn -tables>
"Sets `new-tables` to config"
[new-tables]
(-> *config*
(assoc :tables new-tables)
(-set>)))
(defn <db-settings-
"Returns db settings"
[]
(:db-settings *config*))
(defn -db-settings>
"Sets db settings"
[new-db-settings]
(-> *config*
(assoc :db-settings new-db-settings)
(-set>)))
(defonce ^:dynamic ^:private *config* (-default))