You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to propose an update on how custom validator are registered within Grape. Actually, its based on an inherited hook that computes a short name based on the class's name. It works great but I think that setting a convention would simplify the process and the overall understanding of custom validators.
Basically, I'm suggesting that custom validator should be declared the same way has the built-in ones:
Declared In Grape::Validations::Validators modules
Class name must end with Validator
That way, instead of relying on the inherited hook, we could just call Grape::Validations::Validators.const_get(computed_short_name) when compiling. We're already using this pattern for versioning and coercing
It's not explicitly said in our documentation but right now anyone can add custom versioners and coercers by following the convention. In addition, parsers, formatters and error_formatters could also benefit from a convention and ease customization. In lower versions, we had Grape::Util::Registrable but I removed it not long ago since it wasn't really documented.
In any case, I've created a PR that applies Grape's convention and surprisingly its 🟢. That means that we don't have any tests that tries to load a real custom validator. I'll check that out.
Thanks everyone.
The text was updated successfully, but these errors were encountered:
I would like to propose an update on how custom validator are registered within Grape. Actually, its based on an inherited hook that computes a short name based on the class's name. It works great but I think that setting a convention would simplify the process and the overall understanding of custom validators.
Basically, I'm suggesting that custom validator should be declared the same way has the built-in ones:
Grape::Validations::Validators
modulesValidator
That way, instead of relying on the inherited hook, we could just call
Grape::Validations::Validators.const_get(computed_short_name)
when compiling. We're already using this pattern for versioning and coercingIt's not explicitly said in our documentation but right now anyone can add custom versioners and coercers by following the convention. In addition, parsers, formatters and error_formatters could also benefit from a convention and ease customization. In lower versions, we had
Grape::Util::Registrable
but I removed it not long ago since it wasn't really documented.In any case, I've created a PR that applies Grape's convention and surprisingly its 🟢. That means that we don't have any tests that tries to load a real custom validator. I'll check that out.
Thanks everyone.
The text was updated successfully, but these errors were encountered: