Skip to content

Instantly share code, notes, and snippets.

@jaen

jaen/test.clj Secret

Created November 19, 2015 16:14
Show Gist options
  • Save jaen/d0fbc37c03933bc286c0 to your computer and use it in GitHub Desktop.
Save jaen/d0fbc37c03933bc286c0 to your computer and use it in GitHub Desktop.
(let [make-coercer (fn [schema coercion-matcher]
(spec/run-checker
(fn [s params]
(let [checker (spec/checker (s/spec s) params)]
(if-let [coercer (coercion-matcher s)]
(fn [x]
(macros/try-catchall
(let [check-result (checker x)]
(if (utils/error? check-result)
check-result
(coercer check-result)))
(catch t (macros/validation-error s x t))))
checker)))
true
schema))
schema {:date DateTime}
value {:date (time/now)}
coercion-matcher {DateTime (fn [date-time]
(let [unix-timestamp (time-coerce/to-long date-time)]
(* unix-timestamp DATE-TIME-CONVERSION-FACTOR)))}
coercer (make-coercer schema coercion-matcher)]
(coercer value))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment