I'm following DCI to structure the behavior of a new Rails application, but I have some doubts about where to put the validations.
Traditionally, if you're going to manage your data using ActiveRecord models, validations are defined at the particular class that inherits from AR, and they seem to fit right as part of the data layer.
However, to my eyes it makes sense to have certain validations that only happens under a specific role, and they should only be checked if the object is on that context, being ignored in all the other cases. Which basically means that those validations should be defined at particular roles, and the object should be extended with those role modules when it's being used on the context where it makes sense.
Do you think it's a good idea to keep those validations at the roles? If so, how do you declare them without contaminating the other instances of the same class than the object? If I want to use the ActiveRecord validations, they are declared at class level, so I can't attach them to the object individually, being forced to use a re-declaration of the "validate" instance method on the role module (attaching the errors to the errors array of the object directly), or some similar technique.
user.extend(Seller)
What I'm wondering is if roles should define things like extra validations, and if so, how people do it without infecting the class. Thanks! – Gaidano