Sha256: 7dfd21c123aaf242bb8e84ac16cbf01331251b41582375aeda4d0dc5b499886e
Contents?: true
Size: 1.67 KB
Versions: 4
Compression:
Stored size: 1.67 KB
Contents
= Valuedate Validates values using a schema. Source[http://github.com/splattael/valuedate] | RDoc[http://rdoc.info/projects/splattael/valuedate] | Metrics[http://getcaliper.com/caliper/project?repo=git%3A%2F%2Fgithub.com%2Fsplattael%2Fvaluedate.git] == Usage schema = Valuedate.schema do value.is_a(String).equals("test") end schema.validate("test") # => true schema.validate("fail") # => false schema.validate(23) # => false deep = Valuedate.schema do value.hash( :type => value.is_a(String), :value => value.hash( :src => value.is_a(String), :height => optional_value.is_a(Fixnum), :width => optional_value.is_a(Fixnum) ) ) end deep.validate( :type => "image", :value => { :src => "/bold.gif", :height => 80, :width => 80 } ) # => true # :height and width are optional deep.validate(:type => "image", :value => { :src => "/bold.gif" }) # => true == Matchers Following matchers are defined: * is_a(Class) * equals(expected) * any(list of validators) * in(range, array or anything that responds_to #include?) * is { |value| boolean } * not { |value| boolean } === Missing matchers? Use #is and #not: schema = Valuedate.schema do value.hash( :array => value.not { |value| value.empty? }, :rgb => value.is { |value| value.size == 3 } ) end schema.validate(:array => [1], :rgb => [1,2,3]) # => true schema.validate(:array => [1], :rgb => [1,2]) # => false == Defining matchers Valuedate.matcher(:equals) { |value, expected| value == expected } == Install git clone ... rake install == Authors * Peter Suschlik == TODO * Implement and aggregate errors
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
valuedate-0.0.6 | README.rdoc |
valuedate-0.0.5 | README.rdoc |
valuedate-0.0.4 | README.rdoc |
valuedate-0.0.3 | README.rdoc |