-
-
Save glenjamin/548670fe5855c7943d81 to your computer and use it in GitHub Desktop.
Crazily indented clojure macro
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
(ns http) | |
(defn post [a b] "test") | |
(def ^:private http-extras | |
{:insecure? true, :debug true}) | |
(let [orig http/post | |
f (fn [u r] (orig u (merge r http-extras)))] | |
(defmacro patch-http | |
"Monkey-patch HTTP requests to do stuff we want" | |
[& body] | |
`(with-redefs [http/post ~f] ~@body))) | |
(defn get-token | |
"Get an OAuth request token" | |
[callback] | |
(patch-http | |
(+ 1 2))) |
edw
commented
Mar 17, 2013
(defmacro patch-http
"Monkey-patch HTTP requests to do stuff we want"
[& body]
(let [f #(clj-http.client/post %1 (assoc %2 :insecure? true :debug true))]
`(with-redefs [http/post ~f] ~@body)))
(let [orig-post clj-http.client/post
f #(orig-post %1 (assoc %2 :insecure? true :debug true))]
(defmacro patch-http
"Monkey-patch HTTP requests to do stuff we want"
[& body] `(with-redefs [http/post ~f] ~@body)))
(ns http)
(defn post [a b] "test")
(def ^:private http-extras
{:insecure? true, :debug true})
(let [orig-post http/post]
(defmacro patch-http
"Monkey-patch HTTP requests to do stuff we want"
[& body]
`(with-redefs [http/post #(~orig-post %1 (merge %2 http-extras))]
~@body)))
(defn get-token
"Get an OAuth request token"
[callback]
(let [orig-post http/post]
(with-redefs [http/post #(orig-post %1 (merge %2 http-extras))]
(+ 1 2))))
(defn get-token-2
"Get an OAuth request token"
[callback]
(patch-http (+ 1 2)))
(ns http)
(defn post [a b] [a b])
(def ^:private http-extras
{:insecure? true, :debug true})
(let [orig-post http/post]
(defmacro patch-http
"Monkey-patch HTTP requests to do stuff we want"
[& body]
`(with-redefs [http/post #(~orig-post %1 (merge %2 http-extras))]
~@body)))
(defn get-token
"Get an OAuth request token"
[callback]
(let [orig-post http/post]
(with-redefs [http/post #(orig-post %1 (merge %2 http-extras))]
(post "/foo" {}))))
(defn get-token-2
"Get an OAuth request token"
[callback]
(patch-http (post "/foo" {})))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment