Quiver icon indicating copy to clipboard operation
Quiver copied to clipboard

[BUG]Can't create custom validator.

Open bedranfleck opened this issue 5 years ago • 5 comments

As of October 2019, I can't create a custom validator inheriting from Validator. It seems the validate function is not declared as open, but public. When I try to subclass it and implement a custom validate function, I get the following error:

Overriding non-open instance method outside of its defining module

@heitorgcosta @LucianoPAlmeida would you kindly fix this?

bedranfleck avatar Oct 07 '19 21:10 bedranfleck

I will proceed to open a pull request with this change.

bedranfleck avatar Oct 07 '19 21:10 bedranfleck

@affbedran Humm, now I'm understanding it better ... maybe a solution to create a custom validation that doesn't require an API change could be to use a custom closure-based validator. You can see an example here :))

LucianoPAlmeida avatar Oct 08 '19 01:10 LucianoPAlmeida

@LucianoPAlmeida I see, but wouldn't that be more of a workaround? What if I need to implement a more robust validation? There are cases when subclassing is better.

bedranfleck avatar Oct 08 '19 17:10 bedranfleck

I don't see as a workaround, more like some generic point customization, where you can do any kind of validation in a very easy way. I agree that maybe some few robuts validations e.g. zip code maybe better subclass, but most cases just a closure would be simple enough :))

LucianoPAlmeida avatar Oct 08 '19 18:10 LucianoPAlmeida

I see what you mean by that, but I still think it should be the dev's choice. If a complex case arises, and subclassing is somehow needed, the developer is put between a rock and a hard place.

bedranfleck avatar Nov 18 '19 16:11 bedranfleck