Where to conduct checks after the development of DCI?

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 .

+7
source share
1 answer

It depends on the validations / rules in question. The main purpose of DCI is to separate what the system (domain model) from what the system does (functionality) if the rules are associated with the domain model. For example. rules for greeting SSN, then it should be part of the data objects. On the other hand, if the rules are related to the functionality of the system. the user is allowed to order only two super-deposit products every week, then this is a matter of context

+4
source

All Articles