You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
c4k-common/src/main/clj/dda/c4k_common/yaml.clj

32 lines
806 B
Clojure

3 years ago
(ns dda.c4k-common.yaml
(:require
[clojure.java.io :as io]
[clj-yaml.core :as yaml]
[clojure.walk]
[orchestra.core :refer [defn-spec]]
3 years ago
[orchestra.spec.test :as st]))
3 years ago
(defn-spec cast-lazy-seq-to-vec vector?
[lazy-seq map?]
(clojure.walk/postwalk #(if (instance? clojure.lang.LazySeq %)
(into [] %)
%) lazy-seq))
(defn-spec from-string map? [input string?]
(cast-lazy-seq-to-vec (yaml/parse-string input)))
(defn-spec to-string string? [edn map?]
3 years ago
(yaml/generate-string edn :dumper-options {:flow-style :block}))
(defn dispatch-by-resource-name
3 years ago
[resource]
:clj)
3 years ago
3 years ago
(defmulti load-resource dispatch-by-resource-name)
(defmethod load-resource :clj [resource-name]
(slurp (io/resource resource-name)))
(st/instrument)