Created
January 18, 2013 03:11
-
-
Save XPherior/4562064 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 dire-examples.core | |
(:require [dire.core :refer [with-precondition! with-postcondition!]])) | |
(defn save-user [& {:keys [username email password state]}] | |
"Persist the user to a database here." | |
:ok ;Or :not-ok | |
) | |
(with-precondition! #'save-user | |
:legal-username-length | |
(fn [& {:keys [username]}] | |
(let [length (count username)] | |
(and (> length 4) (< length 11))))) | |
(with-precondition! #'save-user | |
:well-formed-password | |
(fn [& {:keys [password]}] | |
(and (> (count password) 6) (re-matches #".*\d.*" password)))) | |
(with-precondition! #'save-user | |
:well-formed-email | |
(fn [& {:keys [email]}] | |
(re-matches #"\w+@\w+\.\w+" "[email protected]"))) | |
(with-precondition! #'save-user | |
:legal-state-abbreviation | |
(fn [& {:keys [state]}] | |
(re-matches #"[A-Z]{2}" state))) | |
(with-postcondition! #'save-user | |
:successful-save | |
(fn [result] | |
(= result :ok))) | |
(save-user :username "XPherior" :email "[email protected]" :password "mikemike4" :state "PA") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment