Skip to content

Instantly share code, notes, and snippets.

@Deraen
Last active August 29, 2015 13:59
Show Gist options
  • Save Deraen/10586089 to your computer and use it in GitHub Desktop.
Save Deraen/10586089 to your computer and use it in GitHub Desktop.
Indent test
(defmethod restructure-param :path-params
[_ {:keys [lets letks parameters] :as acc}]
"restructures path-params by plumbing letk notation. generates
synthetic defs for the models. example:
:path-params [id :- long name :- string]"
(if-let [path-params (:path-params parameters)]
(let [schema (fnk-schema path-params)
model-name (gensym "path-params-")
_ (eval `(def ~model-name ~schema))
coerced-model (gensym)]
(assoc acc
:lets (into lets [coerced-model `(schema/coerce!
~schema
(:route-params ~+compojure-api-request+)
:query)])
:parameters (-> parameters
(dissoc :path-params)
(update-in [:parameters] conj
{:type :path
:model (eval `(var ~model-name))}))
:letks (into letks [path-params coerced-model])))))
(defn- destructure-compojure-api-request [lets arg]
(cond
(vector? arg) [lets (into arg [:as +compojure-api-request+])]
(map? arg) (if-let [as (:as arg)]
[(conj lets +compojure-api-request+ as) arg]
[lets (merge arg [:as +compojure-api-request+])])
(symbol? arg) [(conj lets +compojure-api-request+ arg) arg]
:else (throw
(runtimeexception.
(str "unknown compojure destruction synxax: " arg)))))
;; Vim settings:
;; let g:clojure_fuzzy_indent_patterns=['^GET', '^POST', '^PUT', '^DELETË́', '^ANY', '^HEAD', '^PATCH', '^OPTIONS']
;; autocmd FileType clojure setlocal lispwords+=describe,it,testing,facts,fact,provided
(GET* "/echo" []
:return QueryParams
:query [query QueryParams]
(ok query))
(GET*
"/echo" []
:return QueryParams
:query [query QueryParams]
(ok query))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment