-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.clj
47 lines (31 loc) · 807 Bytes
/
utils.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
(ns hicosql.utils
(:require [clojure.string :as string]
[clojure.java.io :as io]
[yaml.core :as yaml]))
;; BASE
(defn read-resource [path]
(slurp
(or (io/resource path)
(throw (Exception. (str "Cannot open resource: " path))))))
(defn parse-yaml [data]
(yaml/parse-string data :keywords false))
(defn read-yaml [path]
(parse-yaml (read-resource path)))
;; STRINGS
(defn str->key
" \"&key\" -> key "
[s]
(subs s 1))
(defn function? [key]
(re-matches #"[a-zA-Z0-9_]+\([a-zA-Z0-9_, ]+\)" key))
;; deprecated
(defn templated? [key]
(string/includes? key ":"))
(defn original-name
"req:template -> req"
[key]
(-> key (string/split #":") first))
(defn template-name
"req:templ -> templ"
[key]
(-> key (string/split #":") second))