-
Notifications
You must be signed in to change notification settings - Fork 1
/
core.clj
45 lines (31 loc) · 1022 Bytes
/
core.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
(ns enviable.core
(:require [enviable.reader :as reader]
[enviable.component :as component]
[clojure.string :as str]))
(def var reader/var)
(def parse-with reader/parse-with)
(def default-to reader/default-to)
(def is-optional reader/is-optional)
(def describe reader/describe)
(def error? reader/error?)
(def read-env reader/read-env)
(def configure-system component/configure-system)
(def Configurable component/Configurable)
(def configuration component/configuration)
(def with-configuration component/with-configuration)
;; Useful Parsers TODO move to separate ns
(defn- wrap-parser [parser]
(fn [var]
(parse-with var parser)))
(defn- parse-int [s]
(Integer/parseInt s))
(defn- parse-bool [s]
(case (str/lower-case s)
"true" true
"false" false
nil))
(defn- parse-double [s]
(Double/parseDouble s))
(def int-var (comp (wrap-parser parse-int) var))
(def double-var (comp (wrap-parser parse-double) var))
(def bool-var (comp (wrap-parser parse-bool) var))