-
-
Save KirinDave/c9e6eb3c117db6eb7dca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro state [& forms] | |
(let [state-opts (apply hash-map forms) | |
opts (resolve-states (merge state-standards state-opts)) | |
has-body? (:body opts)] | |
(if-not has-body? | |
`(fn [& [ {request# :request | |
handler# :handler | |
response# :response :as args#}]] | |
(let [test# ~(:test opts) | |
test-result# (test# handler# request#) | |
result# (or (:result test-result#) | |
test-result#) | |
plan# (if result# | |
~(:yes opts) | |
~(:no opts)) | |
nresponse# (if (map? test-result#) | |
(update-response test-result# response#) | |
response#) | |
forward-args# {:request request# | |
:handler handler# | |
:response nresponse#}] | |
(println "Intermediate: " test-result# " -> " result#) ; For debugging | |
(cond | |
(map? plan#) plan# | |
(instance? clojure.lang.IFn plan#) (apply plan# (list args#)) | |
(var? plan#) (apply plan# (list forward-args#)) | |
(keyword? plan#) (list result# plan#) | |
:default plan#) | |
)) | |
(throw (Exception. "Not ready yet!"))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment