A dry-rb gem that allows powerful data validation based on predicate logic in ruby.
Unlike other, well known, validation solutions in Ruby, dry-validation takes a different approach and focuses a lot on explicitness, clarity and precision of validation logic. It is designed to work with any data input, whether it’s a simple hash, an array or a complex object with deeply nested data.
It is based on the idea that each validation is encapsulated by a simple, stateless predicate that receives some input and returns either true or false. Those predicates are encapsulated by rules which can be composed together using predicate logic. This means you can use the common logic operators to build up a validation schema.
Validations can be described with great precision, dry-validation eliminates ambiguous concepts like presence validation where we can’t really say whether some attribute or key is missing or it’s just that the value is nil.
In dry-validation type-safety is a first-class feature, something that’s completely missing in other validation libraries, and it’s an important and useful feature. It means you can compose a validation that relies on the type of a given value. For example it makes no sense to validate each element of an array when it turns out to be an empty string.