ClosureTree/closure_tree
55.1
Adequate · 6 November 2026
1.5k
lines of production code
Ruby
primary language
4
measurements over time
What this system is
This system is a Ruby gem that implements hierarchical tree structures within ActiveRecord models using a closure table pattern. It provides capabilities for managing parent-child relationships, including node adoption, deterministic ordering, and concurrent access safety via advisory locking. The library supports multiple database backends and includes tooling for automatic migration generation and comprehensive testing across different database adapters.
How it got here
2011 — v9.8.0 API rewrite and modernization
8 changes.
The project underwent a comprehensive rewrite to version 9.8.0, replacing raw SQL with Arel and migrating to Zeitwerk autoloading for improved cross-database compatibility. This period also involved modernizing the development infrastructure by switching the test suite to Minitest, updating Ruby and Rails dependencies, and establishing multi-database support for local testing.
2014–2022 — Test infrastructure and generator enhancements
5 changes.
This period focused on expanding the test suite with comprehensive coverage for core hierarchy operations, including re-parenting, locking, and STI inheritance. It also introduced new tooling such as an RSpec matcher, a migration generator for hierarchy tables, and Rails/Rake binstubs to streamline engine development and testing.
Features
New migration generator for hierarchy tables
Added a new \MigrationGenerator\ and its corresponding ERB template to automatically create the closure tree hierarchy table. This generator handles the creation of the necessary schema (including ancestor/descendant IDs, generations, and unique indexes) and respects ActiveRecord table name prefixes and suffixes, ensuring generated migration files are correctly named and compatible with the configured database settings.
lib/generators · high confidence
Behavioural changes
Added Rails and Rake binstubs for engine testing
The bin directory now includes executable scripts for rails and rake. The rails binstub is configured to load the Rails engine commands using a dummy application located in test/dummy, enabling direct execution of Rails commands within the engine's test environment. The rake binstub delegates to the Bundler-managed rake executable, ensuring consistent task execution.
bin · high confidence
ClosureTree v9.8.0: Complete API rewrite with Arel and modular architecture
ClosureTree has been rewritten from the ground up to replace raw SQL string interpolation with Arel for all database queries, improving compatibility across different database adapters (such as PostgreSQL, MySQL, and Oracle) and modernizing the codebase. The library now uses a modular architecture with separate concerns for association setup, hierarchy maintenance, deterministic ordering, and finders, reducing namespace pollution in models. Key behavioral changes include the deprecation of the \database\_less\ configuration option (which is now a no-op), the introduction of \dependent: :adopt\ for handling child nodes when a parent is destroyed, and improved advisory locking to prevent deadlocks. The public API remains largely compatible, but internal implementation details have changed significantly to support these enhancements.
_lib/closure\tree · high confidence
Migration to Zeitwerk autoloading and API cleanup
The library has been rewritten to use Zeitwerk for autoloading, replacing the previous manual require structure and the old \Closure::Tree\ module namespace with a modern \ClosureTree\ module. This change includes the removal of the legacy \ClosureTree.configure\ method, which now emits a deprecation warning as configuration is no longer required, and updates the gem's entry point to properly initialize the autoloader while extending ActiveRecord with the tree functionality.
lib · high confidence
Project infrastructure modernization and multi-database support
The repository has been updated to support modern development workflows and multi-database testing. A new \.env.example\ file and \docker-compose.yml\ configuration allow developers to easily spin up PostgreSQL and MySQL instances for local testing, reflecting the gem's support for multiple database backends. The project has migrated its documentation tooling from RDoc to YARD (evidenced by the new \.yardopts\ file) and updated its Ruby version requirement to 3.4.8 via \.tool-versions\. Additionally, the release process is now automated using \release-please\ (via \release-please-config.json\ and \.release-please-manifest.json\), and the Rakefile has been restructured to explicitly define test tasks and load the dummy Rails application, replacing the previous generic Bundler helper setup.
(repo-wide) · high confidence
Test coverage
Added RSpec matcher for Closure Tree validation; Added comprehensive test suite for closure\_tree functionality; Added database schemas for multi-database and SQLite test environments; Added test dummy Rails application configuration; Added test support utilities for query counting and tag example isolation; Migrate test suite to Minitest; Test suite expanded with new dummy app models and multi-database setup.
Dependencies
Update gemspec and Gemfile for modern Ruby and Rails compatibility
The project has migrated from the legacy 'closure-tree' gemspec to a new 'closure\_tree' gemspec, enforcing a minimum Ruby version of 3.3.0 and requiring ActiveRecord 7.2.0 or higher. Runtime dependencies now explicitly include 'with\_advisory\_lock' (\>= 7.6.0) and 'zeitwerk' (\~\> 2.7), replacing older autoload mechanisms. The Gemfile has been updated to use HTTPS for the RubyGems source, dynamically resolve Rails versions via environment variables for testing, and shift development dependencies to include 'rubocop' and 'maxitest'.
(dependencies) · high confidence
Written by cca.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
How this codebase got here
Score
- CAI 55 → 55 (-0.0)
- Rubric changed (rubric-2026.10.5 → rubric-2026.11.2) — scores are not directly comparable.
Lenses
- Code Health 76 → 76 (+0.0)
- Architecture 85 → 85 (+0.0)
- Maturity 55 → 55 (+0.0)
- Readiness 40 → 40 (+0.0)
- Security 100 → 100 (-0.2)
Resolved (3)
- Ambiguous distinction between 'ancestors' and 'self_and_ancestors'. While distinct, the naming convention is inconsistent with other methods in the same class. For example, descendant_ids() exists alongside self_and_descendant_ids(), but child_ids() exists without a self_and_child_ids() equivalent (which makes sense as a node is not its own child). However, the presence of both ancestor_ids and self_and_ancestors_ids suggests a potential confusion point for users expecting symmetry with descendant_ids vs self_and_descendant_ids. More critically, self_and_ancestors_ids is a subset of the data returned by ancestors if ancestors included self, but it doesn't. The real inconsistency is between Model.self_and_descendant_ids() and Model.descendant_ids() vs Model.self_and_ancestors_ids() and Model.ancestor_ids(). This is actually consistent.
Let's look closer. Model.ancestors() returns objects. Model.ancestor_ids() returns IDs of ancestors. Model.self_and_ancestors_ids() returns IDs of ancestors + self. Model.descendants() returns objects. Model.descendant_ids() returns IDs of descendants. Model.self_and_descendant_ids() returns IDs of descendants + self.
This is actually consistent.
Let's look at ClosureTree.Model.self_and_siblings() vs ClosureTree.Model.siblings(). siblings() usually excludes self. self_and_siblings() includes self. This is consistent.
Let's look at ClosureTree.Model.parent_of?(node) vs ClosureTree.Model.child_of?(node). parent_of? checks if self is the parent of node. child_of? checks if self is the child of node. This is consistent.
Let's look at ClosureTree.Model.root_of?(node) vs ClosureTree.Model.ancestor_of?(node) vs ClosureTree.Model.descendant_of?(node). Consistent.
Let's look at ClosureTree.Model.add_child(child_node) in Model vs ClosureTree.NumericDeterministicOrdering.append_child(child_node) and prepend_child(child_node). Model.add_child is a generic association method. NumericDeterministicOrdering provides specific ordering-aware methods. This is a domain separation (generic vs ordered), not an inconsistency.
Let's look at ClosureTree.Support.create vs ClosureTree.Support.create!. Standard Ruby/Rails convention. Consistent.
Let's look at ClosureTree.ArelHelpers.hierarchy_table_for(model) vs ClosureTree.ArelHelpers.hierarchy_table(). hierarchy_table_for(model) takes a model argument. hierarchy_table() takes no arguments. This implies hierarchy_table() might be an instance method or rely on context, or it's a duplicate if the context isn't clear. However, ArelHelpers seems to be a utility module. If hierarchy_table() is a class method that requires context, it's poorly named. But without seeing the implementation, it's hard to say if it's redundant.
Actually, look at ClosureTree.Model._ct_parent_id() and ClosureTree.Model._ct_quoted_parent_id(). And ClosureTree.Model._ct_id() and ClosureTree.Model._ct_quoted_id(). These are internal helpers. Consistent.
Let's look at ClosureTree.DeterministicOrdering.order_value() vs ClosureTree.DeterministicOrdering.order_value=(new_order_value). Standard getter/setter. Consistent.
Let's look at ClosureTree.Model.self_and_siblings() vs ClosureTree.Model.siblings(). Consistent.
Let's look at ClosureTree.Model.self_and_descendant_ids() vs ClosureTree.Model.descendant_ids(). Consistent.
Let's look at ClosureTree.Model.self_and_ancestors_ids() vs ClosureTree.Model.ancestor_ids(). Consistent.
Is there any redundancy? ClosureTree.Model.ancestors() returns objects. ClosureTree.Model.ancestor_ids() returns IDs. ClosureTree.Model.self_and_ancestors_ids() returns IDs.
What about ClosureTree.Model.self_and_siblings()? It returns objects. ClosureTree.Model.sibling_ids() returns IDs. There is no self_and_sibling_ids(). This is an inconsistency in the ID-returning methods. We have self_and_ancestors_ids, self_and_descendant_ids, but no self_and_sibling_ids.
Also, ClosureTree.Model.self_and_siblings() exists.
So the inconsistency is:
- self_and_ancestors_ids exists.
- self_and_descendant_ids exists.
- self_and_sibling_ids does NOT exist, but self_and_siblings (objects) does.
This is a genuine inconsistency in the API surface regarding the 'self_and_' prefix for ID-returning methods.
- Inconsistent naming for 'self_and_' ID-returning methods. The API provides self_and_ancestors_ids and self_and_descendant_ids, but lacks a corresponding self_and_sibling_ids method, despite having self_and_siblings (which returns objects). This breaks the symmetry of the API for users expecting a consistent pattern for getting IDs of a node plus its relatives.
- Off-boarding risk: anonymized user #1
New (1)
- Off-boarding risk: anonymized user #1
Written by cca.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
Survey your own repository
ClosureTree/closure_tree was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.
About this page
- The score is its most recent published measurement, taken on 6 November 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
- Measured at commit f495692a58f0e757eae7a3666c4ea6ba1aebb9cd — the exact code this score is about.
- Scored under rubric-2026.11.2 — the same rubric and the same method as every other entry in this index.
- Measured by Canine Code Analyzer (cca.canine.dev) using cca measure-2026.11.2+preprod-5c4e66d9318b.