VALIDATIONS 4 RUBY
Vision
Simple Ruby built-in validations.
Purpose.
Provide the developer with a mechanism to verify and validate instances against the types defined by the Ruby interpreter.
Concept.
It is widely known that Ruby, due to its dynamic nature, provides an extremely flexible type checking based on the lack of type checking. This usually proves to be a great advantage for almost every situation every Ruby developer is used to encounter on a daily basis but, sometimes, it is important to assure that specific method should react accordingly a certain given instance.
Several kind of approaches have been proposed in order to address this limitation. The most common chosen approach is the use of testing frameworks (such as Test::Unit, RSpec or Cucumber) in order to partially assure a given argument is properly verified and validated. Certainly, the drawback of this approach is the difficulty and the frustration that appears when the developer starts writing the test cases. Another common approaches are the manual coding of dynamic type checking or duck typing mechanisms within the required methods by using built-in functionality such as Object#is_a?, Object#kind_of?, Object#instance_of? and Object#respond_to? methods. Even tough these latter approaches are more appropriate from a conceptual point of view, the developer would easily realize that the source code becomes repetitive and less transparent.
With the help of “Validator”, a pure Ruby DSL for writing validations, this library proposes a mini-framework that classify the existing built-in types within Ruby into groups, define possible rules for every each of them and allow its validations within any Ruby code. The developer just needs to pass any instance to the validation method with a selected group and additional conditions if required.
Features.
The current version of this library implements these features:
-
Support for each every Ruby built-in type.
-
Support for conditional rules in widely-used types.