Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Enhances ActiveRecord with nested hierarchies.
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
doc Added basic closure table documenation and diagrams.
gemfiles Added Rails 4.2.x support.
lib Added version release notes.
spec Removed JRuby support.
.gitignore Removed Gemfile.lock from .gitignore.
.ruby-version Updated to Ruby 2.2.2.
.travis.yml Removed JRuby support. Added version release notes. Added code of conduct documentation. [ci skip] Updated README, CHANGELOG, and CONTRIBUTING Markdown bullet syntax. […
Gemfile Switched from HTTP to HTTPS when sourcing from RubyGems. [ci skip]
Gemfile.lock Updated gem dependencies.
Guardfile Updated Guardfile to make use of new 'cmd' attribute. Updated company links to be HTTPS instead of HTTP. [ci skip] Added code of conduct documentation. [ci skip]
lineage.gemspec Removed JRuby support.


Gem Version Code Climate GPA Code Climate Coverage Gemnasium Status Travis CI Status Gittip

A implementation of the Closure Table pattern for ActiveRecord models. This uses two tables to maintain the ancestor/descendant relationship for all branches of a particular model. For example, you might have web pages you want to represent in a nested hierarchy which would yield the following table structure:

  • Page (i.e. pages)
  • PageBranch (i.e. page_branches)

Assuming the following page hierarchy:

Branch Graph

The page_branches table would consist of the following data:

Branch Table


  • Database integrity via the Closure Table pattern.


  1. Any of the following Ruby VMs:
  2. Ruby on Rails 4.x.x.


For a secure install, type the following from the command line (recommended):

gem cert --add <(curl -Ls
gem install lineage --trust-policy MediumSecurity

NOTE: A HighSecurity trust policy would be best but MediumSecurity enables signed gem verification while allowing the installation of unsigned dependencies since they are beyond the scope of this gem.

For an insecure install, type the following (not recommended):

gem install lineage

Add the following to your Gemfile:

gem "lineage"


Add the following to any model you wish to enable with lineage support:



To test, run:

bundle exec rspec spec


Read Semantic Versioning for details. Briefly, it means:

  • Patch (x.y.Z) - Incremented for small, backwards compatible bug fixes.
  • Minor (x.Y.z) - Incremented for new, backwards compatible public API enhancements and/or bug fixes.
  • Major (X.y.z) - Incremented for any backwards incompatible public API changes.

Code of Conduct

Please note that this project is released with a CODE OF CONDUCT. By participating in this project you agree to abide by its terms.


Read CONTRIBUTING for details.


Copyright (c) 2010 Alchemists. Read the LICENSE for details.


Read the CHANGELOG for details. Built with Gemsmith.


Developed by Brooke Kuhlmann at Alchemists

Something went wrong with that request. Please try again.