1
1
(ns parkour.cser
2
- (:refer-clojure :exclude [assoc! get])
3
- (:require [parkour.conf :as conf])
4
- (:import [org.apache.hadoop.conf Configuration]
2
+ (:refer-clojure :exclude [assoc! get read-string pr-str])
3
+ (:require [clojure.core :as cc]
4
+ [parkour.conf :as conf])
5
+ (:import [java.io Writer]
6
+ [clojure.lang RT]
7
+ [org.apache.hadoop.conf Configuration]
5
8
[parkour.edn EdnReader]))
6
9
7
10
(def ^:internal ^:dynamic *conf*
8
11
" Configuration of job being executed/configured during job configuration
9
12
de/serialization."
10
13
nil )
11
14
15
+ (defmacro ^:private with-conf
16
+ " Enter dynamic cser context of `conf` for `body` forms."
17
+ [conf & body] `(binding [*conf* (conf/ig ~conf)] ~@body))
18
+
19
+ (defn ^:private read-string*
20
+ " Like core `edn/read-string`, but using cser/EDN reader implementation."
21
+ ([s] (read-string* {:eof nil, :readers *data-readers*} s))
22
+ ([opts s] (when s (EdnReader/readString s opts))))
23
+
24
+ (defn read-string
25
+ " Like core `edn/read-string`, but using cser/EDN reader implementation in the
26
+ cser context of `conf`."
27
+ ([conf s] (with-conf conf (read-string* s)))
28
+ ([conf opts s] (with-conf conf (read-string* opts s))))
29
+
30
+ (defn pr-str
31
+ " Like core `pr-str`, but in the cser context of `conf`."
32
+ [conf & xs] (with-conf conf (apply cc/pr-str xs)))
33
+
12
34
(defn ^:private assoc!*
13
35
" Internal implementation for `assoc!`."
14
36
([conf key val]
15
- (conf/assoc! conf key (pr-str val)))
37
+ (conf/assoc! conf key (cc/ pr-str val)))
16
38
([conf key val & kvs]
17
39
(let [conf (assoc!* conf key val)]
18
40
(if (empty? kvs)
@@ -23,24 +45,15 @@ de/serialization."
23
45
" Set `key` in `conf` to cser/EDN representation of `val`."
24
46
{:tag `Configuration}
25
47
([conf] conf)
26
- ([conf key val]
27
- (binding [*conf* conf]
28
- (assoc!* conf key val)))
29
- ([conf key val & kvs]
30
- (binding [*conf* conf]
31
- (apply assoc!* conf key val kvs))))
32
-
33
- (defn ^:private edn-read-string
34
- " Like core `edn/read-string`, but using cser/EDN reader implementation."
35
- ([s] (edn-read-string {:eof nil, :readers *data-readers*} s))
36
- ([opts s] (when s (EdnReader/readString s opts))))
48
+ ([conf key val] (with-conf conf (assoc!* conf key val)))
49
+ ([conf key val & kvs] (with-conf conf (apply assoc!* conf key val kvs))))
37
50
38
51
(defn get
39
52
" Clojure data value for `key` in `conf`."
40
53
([conf key] (get conf key nil ))
41
54
([conf key default ]
42
- (binding [* conf* conf]
55
+ (with- conf conf
43
56
(let [val (conf/get conf key nil )]
44
57
(if (nil? val)
45
58
default
46
- (edn- read-string val))))))
59
+ (read-string* val))))))
0 commit comments