[clj-]obfusk-data - data validation combinator library for clojure
Clojure Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
spec/obfusk/data
src/obfusk/data
.gitignore
README.md
Rakefile
project.clj

README.md

File        : README.md
Maintainer  : Felix C. Stegerman <flx@obfusk.net>
Date        : 2013-02-11

Copyright   : Copyright (C) 2013  Felix C. Stegerman
Version     : 0.0.2-SNAPSHOT

Description

[clj-]obfusk-data - data validation combinator library for clojure

...

(defdata address {}
  (field [:street :number :postal-code :town] [string?])
  (field :country [string?] { :optional true }) )

(defn email? [x] (re-matches #".*@.*\.[a-z]+" x))

(defdata person {}
  (field [:first-name :last-name :phone-number] [string?])
  (field :email [string? email?])
  (field :address [] { :isa [address] }) )

(defunion tree :type {}
  [ :empty ]
  [ :leaf (field :value []) ]
  [ :node (field [:left :right] [] { :isa [#'tree] }) ] )

(valid? tree
  { :type :node
    :left { :type :empty }
    :right { :type :leaf, :value "spam!" } } )
; => true

Specs & Docs

$ rake spec
$ rake docs

TODO

  • write more specs
  • write more docs
  • show isa errors
  • ...

License

GPLv2 [1] or EPLv1 [2].

References

[1] GNU General Public License, version 2 --- http://www.opensource.org/licenses/GPL-2.0

[2] Eclipse Public License, version 1 --- http://www.opensource.org/licenses/EPL-1.0