-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add before_validation,after_validation options to hook into the validation process #77
Add before_validation,after_validation options to hook into the validation process #77
Conversation
Should we name these |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is cool! It's great to see it used to implement insert_property_defaults
.
Should we name these
before_object_validation
/after_object_validation
to make clear that this is only useful when validating a Hash? 🤔
What do you think about before_property_validation
/after_property_validation
? That is consistent with insert_property_defaults
.
because property_schema might not be a hash here
I was trying to implement handling |
This is useful if you want to act on things like "required" or so in the parent schema or a property
I have changed the hook signature so that the parent schema is passed as well. proc { |data, property, property_schema, schema| … } |
Thanks @ahx! |
Released in 0.2.16 |
@davishmcclurg That it so cool. |
This adds
before_validation
,after_validation
options to modify data before or after validation. Theinsert_property_defaults
now is one of these before hooks.One use case of this is to parse data based on your JSON Schema before or after the validation is run.
The after_validation option should basically solve #49.
In it's current state this only works when validating objects. 😬 What do you think?