I have several ActiveRecord models that contain email addresses and I’d
like to be able to DRY up the validation for them so I only have to put
the appropriate regex in one place. Currently each model has its own
“validates_format_of” with the same regex provided for the appropriate
One option is to use composed_of - would this work for me? I’d need
to compose each email field as an EmailAddress model object in my
Alternatively, there seems to be an opportunity here for declaring
validations that span models - either by naming them, or pointing to a
method somewhere, etc.
Then I could just say “validates_format_of by using this code that I’m
referencing” in my model objects.