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:

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

TODO