Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Ruby ORM that uses plain ruby objects and doesn't require you to inherit from a base class?

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:

Plain C# classes

Are added to a database context class here:

Plain C# classes added to db class

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?

like image 217
Graham Conzett Avatar asked Nov 14 '22 04:11

Graham Conzett


1 Answers

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. :(

like image 147
Guilherme Franco Avatar answered Dec 19 '22 18:12

Guilherme Franco