Skip to content
Browse files

Changed wrap-reload to automatically reload modified source files

  • Loading branch information...
1 parent 9841dfd commit f39e24da7e97dd7354f47c16f160322cca35986d @weavejester weavejester committed
View
3 ring-devel/project.clj
@@ -3,4 +3,5 @@
:url "http://github.com/mmcgrana/ring"
:dependencies [[ring/ring-core "0.3.11"]
[hiccup "0.3.6"]
- [clj-stacktrace "0.2.2"]])
+ [clj-stacktrace "0.2.2"]
+ [ns-tracker "0.1.1"]])
View
26 ring-devel/src/ring/middleware/reload.clj
@@ -1,14 +1,18 @@
(ns ring.middleware.reload
- "Reload namespaces before requests.")
+ "Reload modified namespaces on the fly."
+ (:use [ns-tracker.core :only (ns-tracker)]))
(defn wrap-reload
- "Wrap an app such that before a request is passed to the app, each namespace
- identified by syms in reloadables is reloaded.
- Currently this requires that the namespaces in question are being (re)loaded
- from un-jarred source files, as apposed to source files in jars or compiled
- classes."
- [app reloadables]
- (fn [req]
- (doseq [ns-sym reloadables]
- (require ns-sym :reload))
- (app req)))
+ "Reload namespaces of modified files before the request is passed to the
+ supplied handler.
+
+ Takes the following options:
+ :dirs - A list of directories that contain the source files.
+ Defaults to [\"src\"]."
+ [handler & [options]]
+ (let [source-dirs (:dirs options ["src"])
+ modified-namespaces (ns-tracker source-dirs)]
+ (fn [request]
+ (doseq [ns-sym (modified-namespaces)]
+ (require ns-sym :reload))
+ (handler request))))
View
9 ring-devel/test/ring/middleware/test/reload.clj
@@ -2,8 +2,7 @@
(:use clojure.test
ring.middleware.reload))
-(def app
- (wrap-reload (constantly :response) '(ring.middleware.reload)))
-
-(deftest wrap-reload-smoke
- (is (= :response (app :request))))
+(deftest wrap-reload-smoke-test
+ (let [handler (wrap-reload identity)
+ request {:http-method :get, :uri "/"}]
+ (is (= (handler request) request))))

0 comments on commit f39e24d

Please sign in to comment.
Something went wrong with that request. Please try again.