Created
July 10, 2012 16:31
-
-
Save longfin/3084489 to your computer and use it in GitHub Desktop.
protocol example
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
(defprotocol IDocumentable | |
"Representable protocol for mongodb's document name" | |
(docname [e])) | |
(defprotocol IEntity | |
"Protocol of whole entity." | |
(add! [e]) | |
(edit! [e]) | |
(remove! [e])) | |
(extend-protocol IDocumentable | |
java.lang.String | |
(docname [e] | |
(lower-case e)) | |
clojure.lang.Symbol | |
(docname [e] | |
(docname (str e))) | |
java.lang.Class | |
(docname [e] | |
(let [fullname (.getName e)] | |
(docname (last (split fullname #"\."))))) | |
warklet.model.IEntity | |
(docname [e] | |
(docname (type e)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment