Controls
Description
Controls encapsulate the logic necessary to identify whether or not a specific action or mutation is acceptable. You can think of our controls as model validations that require more context than our models are allowed to encapsulate.
Models may delegate validation to controls.
Controls should not mutate data under any circumstances.
Controls should serve as a centralized place where we can check the criteria that must be met in order for a certain action or mutation to be permissible.
Controls have been most useful for us when encapsulating complex checks/guards for validating object and guarding against allowing actions in the system. For example, checking if a loan is disbursable requires several different checks and is a good example of a useful control. Controls are also a good way to share/reuse this complex logic. Controls should not be used for simple guards/predicates.
Technology Status at Wunder
Retire. Controls are a practical solution to provide checks that cross model and system boundaries. However, we find today that most system controls can fit into an ActiveRecord validation. If a check does not fit neatly into a model validation, our latest Actor code (Actors V2) is designed to support more flexible error handling using ActiveModel::Errors. These two methods are preferred over Controls.