I'm interested in writing a pure ruby domain model and adding persistence later on in development.
Some tools I've used with other langages like Microsoft's Entity Framework, now let you use plain objects for your domain data models, and then add them to a persistence class later through the use of convention based mapping. For example these plain objects:
Are added to a database context class here:
This can be very usefully not only for separating concerns during testing, but also allows for more manageable code, adherence to the SRP, and the ability to swap out your persistence layer easily should the need ever arise.
I can't find anything that quite fits the bill right now ORM-wise in the ruby sphere. ActiveRecord, DataMapper and Sequel all inherit from a base class tied to those frameworks. Are there any projects in progress, alternative methods or practices to achieve this?
Take a look at this one. It promotes a nice separation of concerns between your domain logic and persistence infrastructure layer. Obviously, it doesn't have all of the fancy ActiveRecord tools yet, but is a nice project and worth a look:
https://github.com/fredwu/datamappify
UPDATE
As we can see by this discussion, unfortunately the project is no longer maintained. :(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With