add spec to yaml.clj and base64.clj
This commit is contained in:
parent
46a6ef85a6
commit
7713afdb38
2 changed files with 25 additions and 12 deletions
|
@ -1,14 +1,21 @@
|
||||||
(ns dda.c4k-common.base64
|
(ns dda.c4k-common.base64
|
||||||
(:import (java.util Base64)))
|
(:import (java.util Base64))
|
||||||
|
(:require
|
||||||
|
[orchestra.core :refer [defn-spec]]
|
||||||
|
[orchestra.spec.test :as st]
|
||||||
|
[clojure.spec.alpha :as s]))
|
||||||
|
|
||||||
(defn encode
|
|
||||||
[string]
|
(defn-spec encode string?
|
||||||
|
[string string?]
|
||||||
(.encodeToString
|
(.encodeToString
|
||||||
(Base64/getEncoder)
|
(Base64/getEncoder)
|
||||||
(.getBytes string "UTF-8")))
|
(.getBytes string "UTF-8")))
|
||||||
|
|
||||||
(defn decode
|
(defn-spec decode string?
|
||||||
[string]
|
[string string?]
|
||||||
(String.
|
(String.
|
||||||
(.decode (Base64/getDecoder) string)
|
(.decode (Base64/getDecoder) string)
|
||||||
"UTF-8"))
|
"UTF-8"))
|
||||||
|
|
||||||
|
(st/instrument)
|
|
@ -2,18 +2,22 @@
|
||||||
(:require
|
(:require
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[clj-yaml.core :as yaml]
|
[clj-yaml.core :as yaml]
|
||||||
[clojure.walk]))
|
[clojure.walk]
|
||||||
|
[orchestra.core :refer [defn-spec]]
|
||||||
|
[orchestra.spec.test :as st]
|
||||||
|
[clojure.spec.alpha :as s]))
|
||||||
|
|
||||||
(defn cast-lazy-seq-to-vec
|
|
||||||
[lazy-seq]
|
(defn-spec cast-lazy-seq-to-vec map?
|
||||||
|
[lazy-seq map?]
|
||||||
(clojure.walk/postwalk #(if (instance? clojure.lang.LazySeq %)
|
(clojure.walk/postwalk #(if (instance? clojure.lang.LazySeq %)
|
||||||
(into [] %)
|
(into [] %)
|
||||||
%) lazy-seq))
|
%) lazy-seq))
|
||||||
|
|
||||||
(defn from-string [input]
|
(defn-spec from-string map? [input string?]
|
||||||
(cast-lazy-seq-to-vec (yaml/parse-string input)))
|
(cast-lazy-seq-to-vec (yaml/parse-string input)))
|
||||||
|
|
||||||
(defn to-string [edn]
|
(defn-spec to-string string? [edn map?]
|
||||||
(yaml/generate-string edn :dumper-options {:flow-style :block}))
|
(yaml/generate-string edn :dumper-options {:flow-style :block}))
|
||||||
|
|
||||||
(defn dispatch-by-resource-name
|
(defn dispatch-by-resource-name
|
||||||
|
@ -24,3 +28,5 @@
|
||||||
|
|
||||||
(defmethod load-resource :clj [resource-name]
|
(defmethod load-resource :clj [resource-name]
|
||||||
(slurp (io/resource resource-name)))
|
(slurp (io/resource resource-name)))
|
||||||
|
|
||||||
|
(st/instrument)
|
Loading…
Reference in a new issue