I am following DCI to structure the behavior of the new Rails application, but I have some doubts as to where to put the checks.
Traditionally, if you intend to manage your data using ActiveRecord models, validations are defined in a specific class that inherits from AR, and they seem to fit as part of the data layer.
However, in my opinion, it makes sense to have certain checks that occur only under a certain role, and they should be checked only if the object is in this context, ignored in all other cases. This basically means that these checks should be defined on specific roles, and this object should be expanded with these role modules when used in a context where it makes sense.
Do you consider it a good idea to keep these validations in roles? If so, how do you declare them without polluting other instances of the same class except the object? If I want to use ActiveRecord checks, they are declared at the class level, so I canโt attach them to the object individually, forcing to use the re-declaration of the validate method in the role module (attaching an error to the object's error array directly) or some similar method .
Carlos Paramio
source share