Skip to content

Instantly share code, notes, and snippets.

@senior
Created December 17, 2013 15:16
Show Gist options
  • Select an option

  • Save senior/8006532 to your computer and use it in GitHub Desktop.

Select an option

Save senior/8006532 to your computer and use it in GitHub Desktop.
wrapped-fn-args
(defmacro with-wrapped-fn-args [bindings & body]
(cond
(zero? (count bindings))
`(do ~@body)
(symbol? (first bindings))
`(let [~(get bindings 0) (atom [])
orig-fn# ~(get bindings 1)]
(with-redefs [~(get bindings 1) (wrap-capture-args orig-fn# ~(get bindings 0))]
(with-wrapped-fn-args ~(subvec bindings 2)
~@body)))
:else (throw+ "with-wrapped-fn-args bindings should be pairs of count-atom-sym and fn-to-wrap with the call-count function")))
;;...
(with-wrapped-fn-args [inserts sql/insert-records
deletes sql/delete-rows
updates sql/update-values]
(add-catalog! (assoc updated-catalog :transaction-uuid new-uuid) nil yesterday)
(is (= #{:resource_params_cache :resource_params :catalog_resources}
(set (map first @inserts))))
(is (= [:catalogs]
(map first @updates)))
(is (= [[:catalog_resources ["catalog_id = ? and type = ? and title = ?" 1 "File" "/etc/foobar"]]]
(remove #(= :edges (first %)) @deletes))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment