Skip to content

Commit

Permalink
WIP: use multimethod for coercion to location
Browse files Browse the repository at this point in the history
  • Loading branch information
ordnungswidrig committed Jun 12, 2012
1 parent 7b43d2f commit 745fb51
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/compojure_rest/resource.clj
Expand Up @@ -182,16 +182,13 @@
(defn =method [method context]
(= (get-in context [:request :request-method]) method))

(defprotocol Location
(to-location [_]))

(extend-protocol Location
String
(to-location [this] {:headers {"Location" this}})
clojure.lang.APersistentMap
(to-location [this] this)
nil
(to-location [this] nil))
(defmulti to-location type)

(defmethod to-location String [uri] {:headers {"Location" uri}})

(defmethod to-location clojure.lang.APersistentMap [this] this)

(defmethod to-location nil [this] this)

(defn -handle-moved [k status {:keys [resource] :as context}]
(if-let [f (k resource)]
Expand Down

0 comments on commit 745fb51

Please sign in to comment.