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

26 lines
662 B
Clojure

3 years ago
(ns dda.c4k-common.yaml
(:require
[clojure.java.io :as io]
[clj-yaml.core :as yaml]
[clojure.walk]))
(defn cast-lazy-seq-to-vec
[lazy-seq]
(clojure.walk/postwalk #(if (instance? clojure.lang.LazySeq %)
(into [] %)
%) lazy-seq))
(defn from-string [input]
(cast-lazy-seq-to-vec (yaml/parse-string input)))
(defn to-string [edn]
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)))