Skip to content

Commit

Permalink
make methods that start with dash inaccessible via api so they can be…
Browse files Browse the repository at this point in the history
… used internally
  • Loading branch information
ninjudd committed May 13, 2013
1 parent 1186c74 commit 5ff4291
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/flatland/wakeful/utils.clj
Expand Up @@ -6,7 +6,7 @@
(not (or (re-find #"-test|test-" ns-name) ;; cake: flatland.wakeful.utils-test, flatland.wakeful.test-utils
(re-find #"(?<![^.])test\.[^.]+$" ns-name)))))) ;; lein: flatland.wakeful.test.utils

(def method-regex #"[\w-]+")
(def method-regex #"\w[\w-]*")

(defn parse-fn-name
"Takes a wakeful function name and parses it. Returns the bare name, without extension, and :read, :write or nil."
Expand All @@ -27,4 +27,4 @@
(assoc meta
:bare-name bare-name
:type type
:args (some meta [:params :arglists]))))
:args (some meta [:params :arglists]))))
4 changes: 4 additions & 0 deletions test/flatland/wakeful/core_test.clj
Expand Up @@ -54,6 +54,10 @@
(testing "Can send JSON as string, not just stream"
(is (= response (handler (request-map (json/generate-string post-data)))))))))

(deftest test-internal-method-inaccessible
(let [handler (wakeful :root "sample" :read wrap-body)]
(is (= nil (handler {:uri "/foo/-foo", :request-method :get})))))

(deftest test-write
(let [handler (wakeful :root "sample" :write wrap-body)]
(let [response (handler {:uri "/foo-1/foo", :request-method :post, :body (json-stream {"foo" 1})})]
Expand Down
7 changes: 6 additions & 1 deletion test/sample/foo.clj
@@ -1,6 +1,11 @@
(ns sample.foo
"This namespace contains two read and two write functions.")

(defn -foo
"This is an internal method that should not be accessible."
[& args]
(prn args))

(defn foo
"This is the foo read method"
[request]
Expand All @@ -19,4 +24,4 @@
(defn bar!
"This is the bar write method"
[request]
[:bar! (:uri request) (:body request) (:route-params request)])
[:bar! (:uri request) (:body request) (:route-params request)])

0 comments on commit 5ff4291

Please sign in to comment.