Migrating inheritance of object to Rails (looking for DRY)

Hello Railers!

Last year I migrated a not-so-complex Zope ZODB application to rails,
within weeks. Now I have a harder task to solve.

ZODB is the object database in Zope, which allow you store, ehem,
object, and simply add attributes.

Now, you hae object that beside acting as object, could also act as
containers for other or similar kind of objects.

Using that approach, we managed to create an inheritable
properties/attributes table used by the parent object, when his child
“condition” is meet.

Let me draw an example:

root
|–Container 1
| |–Page 1
| | |–SubPage 1.1
| | --SubPage 1.2
| --Page 2
| --SubPage 2.1
|
–Container 2
–Container 2.1
–Page 3

The contanier don’t have specific properties, Page it does.
SubPages actualy serve to replace or add new properties to the parent
(Page).

SubPages can’t hold SubPages. In this example we used Pages, but we
could structure also other kind of objects.

We collect that information for /Container checking each Page and
SubPage conditions are meet (time of the day, week, other
conditionals), and build a virtual Page based on the collected
properties (this is passed to other software to use as data).

To solve this is Zope, we coded Each kind of object, and maintina
different codes, so extending the Contanier required reimplement the
code for Page as Containers too, so wasn’t too DRY.

Back on Rails, we are looking to the best approach to achieve this…

Single Table Inheritance (STI)?
Using that we should reduce the “Container” issues with the code, and
reuse them inside Pages (or any other container-like object we
implement later).

acts_as_tree?
To offer parent/child relations, which we need.
But to limit SubPages (which are actualy a Page) we should limit
creation of childrens if !parent.type == “Container” | “Page”, right?

What other things we should consider for this?

Thanks in advance for your time,

Regards,

Luis

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs