Thanks to a some contributions from a friend, we will call him Lance, we were able to make some important updates to the project over the last week. If you have never heard of or used Hyrule please check back soon as I am going to start a new series on using the framework. In the meantime here is a quick intro to the framework.
Hyrule is a validation framework for ColdFusion. Contrary to popular belief it's not just for ORM (Hibernate) based applications. The Hyrule framework will work with ColdFusion 9+ applications that use a model driven behavior for business objects. All this means is that use a class (component) to describe your objects such as user, person or employee.
This framework gives you multiple ways to declare your validation rules or as the framework refers to them, constraints. Once you have defined your constraints you can pass in an object to the framework and it will let you know if it passes validation. This approach gives you a simple way to perform data validation in your object oriented based applications.
This framework was created because there was a real need for it. When I started building most of my applications in a model driven form it became clear that there had to be an easier way of validating data. My inspiration was and still is the Hibernate Validator project from the Java community.
Now let's talk about the changes we made.
Documentation: The download now contains the 1st draft of our documentation. While it isn't perfect I think it's enough to get you started. If you are just getting stated and find anything in the docs confusing please let me know. If you want to view the docs online you can check them out here
Rule Parser: The core rule parsing engine was refactored. This was an important update for us to move forward. The most important change to you is that you no longer need to define a validator for annotation based rules. Annotations, property attributes and the new constraints struct all live in the metadata parser.
Display Name: There are times when humanizing the property name (what we do by default) just won't cut it. Take for instance a user component that has a variable named ssn. When we display the error to the user we want the property to display as Social Security Number. You can use the displayName attribute to override the default property display name. When the required constraint fails the message will read "The field Social Security Number must contain a value."
Constraints Struct: You can now declare constraints using a constraints struct stored in the this scope of an object.
There are two cons to using this approach. First off any variables stored in the this scope are publically exposed. Second, say we have an employee object that extends our user object above. If we added another struct called constraints it would override the parent objects constraints. To avoid this collision you must define all of the constraints individually in a child object.
IsValid Constraint: Instead of adding individual constraints for types like creditcard,email and ssn we implemented a catch all constraint. This will validate any type that the built in isValid() function supports except regex and range, which we already have constraints for. At the property level you must declare this constraint as isValid="type(ssn,email,etc)" but using the constraints struct you can use the type constraint. This is because a property already has an attribute called type to define its data type.
Tests: All of the MxUnit tests have been updated and are green across the board. If you ever have questions on how the constraints work this is a good place to look.
Bug Fixes: There were a ton of bug fixes and a few other enhancements.
I feel really good about where the project is right now. Please grab the source code using the link below and try it out. We could really use your feedback to make this framework better.
https://github.com/cfaddict/hyrule
