UniversalValidator
Installation
Add this line to your application's Gemfile:
gem 'universal_validator'
And then execute:
$ bundle
Or install it yourself as:
$ gem install universal_validator
Usage
require 'universal_validator'
class Command
def foo
...
data = {name: 'bar', age: 200}
...
v = UniversalValidator::Validator.new do |v|
v.add_error_for(:name, 'wrong name') if data[:name] != 'baz'
v.add_error_for(:age, 'wrong age') if data[:age] > 100
end
if v.errors?
p v.errors #=> {:name=>["wrong name"], :age=>["wrong age"]}
p v.errors_for(:name) #=> ["wrong name"]
...
else
...
end
end
end
Versioning
See semver.org
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request