Skip to content

Commit

Permalink
use clojure.tools.reader for clj files
Browse files Browse the repository at this point in the history
  • Loading branch information
David Leatherman committed Mar 25, 2014
1 parent 09cb33c commit 5b81451
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions 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]))
Expand Down Expand Up @@ -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."
Expand All @@ -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)]
Expand Down

0 comments on commit 5b81451

Please sign in to comment.