add spec to yaml.clj and base64.clj

This commit is contained in:
az 2021-10-31 08:51:03 +01:00
parent 46a6ef85a6
commit 7713afdb38
2 changed files with 25 additions and 12 deletions

View file

@ -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)

View file

@ -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)