Validating domain objects

I once heard someone say: Using mixins like this is akin to “cleaning” a messy room by dumping the clutter into six separate junk drawers and slamming them shut.

validating domain objects-47

Refactor to break them down and spread out the logic evenly.

Repeat this process and you’ll end up with a set of simple objects with well defined interfaces working together in a veritable symphony. But after some exploration and practice, I realized that Rails (the framework) doesn’t impede OOP all that much.

Virtus performs coercions only when a value is being assigned.

If you mutate the value later on using its own interfaces then coercion won't be triggered.

You can also specify constraints on relationships, such as making them mandatory or unable exceed a certain number.