Project

valuedate

0.0
No commit activity in last 3 years
No release in over 3 years
Validates values.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 0.10.11
 Project Readme

Valuedate¶ ↑

Validates values using a schema.

Source | RDoc | Metrics

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