[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]
|
["js-yaml" :as yaml]
|
||||||
[clojure.string :as st]
|
[clojure.string :as st]
|
||||||
[orchestra.core :refer-macros [defn-spec]]
|
[orchestra.core :refer-macros [defn-spec]]
|
||||||
|
[shadow.resource :as rc]
|
||||||
[dda.c4k-common.predicate :as cp]))
|
[dda.c4k-common.predicate :as cp]))
|
||||||
|
|
||||||
(defn-spec from-string cp/map-or-seq?
|
(defn-spec from-string cp/map-or-seq?
|
||||||
|
@ -16,8 +17,18 @@
|
||||||
|
|
||||||
(defn-spec dispatch-by-resource-name keyword?
|
(defn-spec dispatch-by-resource-name keyword?
|
||||||
[resource string?]
|
[resource string?]
|
||||||
(keyword (first (st/split resource #"/"))))
|
:cljs)
|
||||||
|
|
||||||
(defmulti load-resource dispatch-by-resource-name)
|
(defmulti load-resource 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)
|
(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