[katello-devel] Custom validators change
Marek Hulan
mhulan at redhat.com
Wed Jan 9 10:53:53 UTC 2013
Hello
During work on bug #820392 I realized that there is a huge number of custom
validators in app/models/. Some of them were in model files some of them in
their own files. I believe that validators are not models so I moved them to
newly created lib/validators/.
This has impact on autoloading them. On few places validators were used like
this
validates :description, :katello_description_format => true
Because classes from lib are not loaded automatically we'd have to either
explicitely require validators we need or we can use another API like this
validates_with Validators::KatelloDescriptionFormatValidator, :attributes
=> :description
which trigers autoloading by using the validator's constant.
I changed all existing code to second variant which loads class via Rails
autoloader. Note that all validators are in module Validators in order they
could be placed in lib/validators/ directory.
You can find more details in pull request 1375 [1].
TL;DR version:
* when adding validator, put it in lib/validators/
* use validates_with
[1] https://github.com/Katello/katello/pull/1375
--
Marek
More information about the katello-devel
mailing list