Skip to content

Commit

Permalink
List validator
Browse files Browse the repository at this point in the history
  • Loading branch information
mmontone committed Aug 30, 2015
1 parent da05eac commit 887646c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions clavier.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
(funcall func)))

(defmacro with-signal-validation-errors ((&optional (signal t)) &body body)
"Enables/disables validation errors in body
Args: - signal(boolean) : If **T**, errors are signaled. If **NIL**, they are not."
`(call-with-signal-validation-errors (lambda () ,@body) ,signal))

(defmacro collecting-validation-errors ((errors found-p) expr &body body)
Expand Down Expand Up @@ -167,6 +170,15 @@
(format nil "~A is not a keyword" object)))
(:metaclass closer-mop:funcallable-standard-class))

(defclass list-validator (type-validator)
()
(:default-initargs
:type 'list
:message (lambda (validator object)
(format nil "~A is not a list" object)))
(:metaclass closer-mop:funcallable-standard-class))


(defclass function-validator (validator)
((function :initarg :function
:accessor validator-function
Expand Down Expand Up @@ -518,6 +530,11 @@
(when message
(list :message (apply #'format nil message args)))))

(defun is-a-list (&optional message &rest args)
(apply #'make-instance 'list-validator
(when message
(list :message (apply #'format nil message args)))))

(defun valid-email (&optional message &rest args)
(apply #'make-instance 'email-validator
(when message
Expand Down
2 changes: 2 additions & 0 deletions package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#:integer-validator
#:symbol-validator
#:keyword-validator
#:list-validator
#:function-validator
#:true-validator
#:false-validator
Expand Down Expand Up @@ -61,6 +62,7 @@
#:is-an-integer
#:is-a-symbol
#:is-a-keyword
#:is-a-list
#:valid-email
#:matches-regex
#:valid-url
Expand Down

0 comments on commit 887646c

Please sign in to comment.