Wednesday, September 7, 2016

Inheriting Attributes in a Tree Data Structure

I just published a new gem, inherited-attributes, for Active Record that works with the Ancestry gem to provide a tree data structure the ability to inherit attributes from their parent node, or farther up the tree.  We've been using this technique for a long time to support configuring our multi-tenant application.

Once the gem is installed, its very simple to configure:




From there, you can access the effective attributes which look up the tree ancestry to find a value to inherit.




There are more options and examples in the gem, including has-one relationships, default values and support for enumerations.

We've found it helpful and writing a gem made this code much easier to test.  What code do you have that would be easier to test as a gem or would be useful to others?

No comments:

Post a Comment