diff --git a/src/carica/core.clj b/src/carica/core.clj index 88533f4..cdbdd00 100644 --- a/src/carica/core.clj +++ b/src/carica/core.clj @@ -1,6 +1,7 @@ (ns carica.core (:use [clojure.java.io :only [reader input-stream] :as io]) (:require [clojure.tools.logging :as log] + [clojure.tools.reader :as clj-reader] [clojure.tools.reader.edn :as edn] [clojure.tools.reader.reader-types :as readers] [clojure.walk :as walk])) @@ -38,6 +39,14 @@ (merge-with merge-nested v1 v2) v2)) +(defn load-with [resource loader] + (try + (-> resource input-stream readers/input-stream-push-back-reader loader) + (catch Throwable t + (log/warn t "error reading config" resource) + (throw + (Exception. (str "error reading config " resource) t))))) + (defmulti load-config "Load and read the config into a map of Clojure maps. Dispatches based on the file extension." @@ -50,12 +59,10 @@ (keyword "carica")))) (defmethod load-config :carica/edn [resource] - (try - (-> resource input-stream readers/input-stream-push-back-reader edn/read) - (catch Throwable t - (log/warn t "error reading config" resource) - (throw - (Exception. (str "error reading config " resource) t))))) + (load-with resource edn/read)) + +(defmethod load-config :carica/clj [resource] + (load-with resource clj-reader/read)) (defmethod load-config :carica/json [resource] (with-open [s (.openStream resource)]