###Validation
An extensive pack of customizable and extensible validation to your objects.
###Installation
$ gem install resize-validation
$ require 'resize-validation'
###Usage
A minimal implementation could be:
Resize::Validation::validate(email: '[email protected]')
# => true
Resize::Validation::validate(string: 5)
# => false
raise custom exception:
Resize::Validation::validate!(integer: 'five')
# => "The input five does not match the rule integer (TypeError)"
A composable implementation could be:
Resize::Validation::validates do |v|
v.validate(integer: 5)
v.validate(uppercase: "NAME")
v.validate(boolean: false)
end
# => true
Resize::Validation::validates do |v|
v.validate(integer: "5")
v.validate(uppercase: "NAME")
v.validate(boolean: false)
end
# => false
Catching errors:
Resize::Validation::validates! do |v|
v.validate(integer: 5)
v.validate(uppercase: "NAME")
v.validate(boolean: false)
end
# => {:status=>true, :errors=>[]}
Resize::Validation::validates! do |v|
v.validate(integer: "5")
v.validate(uppercase: "NAME")
v.validate(boolean: false)
end
# => {:status=>false, :errors=>["The input 5 does not match the rule integer"]}
###Contributing
- Fork it ( https://github.com/Resize/Validation/fork )
- Create your feature branch (
git checkout -b new_feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin new_feature
) - Create a new Pull Request
###License
Copyright © 2014 Londerson Araújo, released under the MIT license