[WIP] Refactor yaml.cljs
Move redundand functionality from modules to common.
This commit is contained in:
parent
ce73df117c
commit
d1f4fb942d
1 changed files with 14 additions and 3 deletions
|
@ -3,6 +3,7 @@
|
|||
["js-yaml" :as yaml]
|
||||
[clojure.string :as st]
|
||||
[orchestra.core :refer-macros [defn-spec]]
|
||||
[shadow.resource :as rc]
|
||||
[dda.c4k-common.predicate :as cp]))
|
||||
|
||||
(defn-spec from-string cp/map-or-seq?
|
||||
|
@ -10,14 +11,24 @@
|
|||
(js->clj (yaml/load input)
|
||||
:keywordize-keys true))
|
||||
|
||||
(defn-spec to-string string?
|
||||
(defn-spec to-string string?
|
||||
[edn cp/map-or-seq?]
|
||||
(yaml/dump (clj->js edn)))
|
||||
|
||||
(defn-spec dispatch-by-resource-name keyword?
|
||||
[resource string?]
|
||||
(keyword (first (st/split resource #"/"))))
|
||||
:cljs)
|
||||
|
||||
(defmulti load-resource dispatch-by-resource-name)
|
||||
|
||||
(defmulti load-as-edn dispatch-by-resource-name)
|
||||
(defmethod load-resource :cljs [allowed-resources resource-name]
|
||||
(if (some #(= % resource-name) allowed-resources)
|
||||
(rc/inline resource-name)
|
||||
(throw (js/Error. "Undefined Resource!"))))
|
||||
|
||||
(defmulti load-as-edn dispatch-by-resource-name)
|
||||
|
||||
(defmethod load-as-edn :cljs [resource-name]
|
||||
(yaml/from-string (yaml/load-resource resource-name)))
|
||||
|
||||
(defmulti allowed-resources dispatch-by-resource-name)
|
Loading…
Reference in a new issue