Case 08 Ruby · Rails · Reusable libraries
Ruby libraries: reusable solutions to backend problems
I turned recurring backend problems into published libraries. I authored hierarchy-tree, validations-skipper and cascade-deleter, and coauthored parsecs and deep-cloning. Each concentrates a responsibility that other applications can reuse.
Context
Alongside applications, I work on tools for problems shared across systems. All five gems are published on RubyGems with named authors and repository links.
Problem
Cloning related records, understanding associations or deleting a hierarchy involves more than an isolated database operation. The relationships and expected behavior need clear boundaries.
For formula evaluation, the Ruby application also needs to communicate with a C++ calculation core.
My responsibility
I created hierarchy-tree, validations-skipper and cascade-deleter. Their public metadata identifies Victor Cordeiro Costa as author.
On parsecs and deep-cloning, authorship is shared with Nilton Vasques and Beatriz Fagundes. My contribution is part of that collective work.
Decision
Keeping responsibilities in small libraries makes it possible to assess each API, its examples and its limits separately from the application using it.
The parsecs Ruby wrapper connects the application to the C++ evaluator; the browser version is covered in the Parsec case.
Alternatives and trade-offs
Present-day analysis written for this site. It is not a record of the alternatives evaluated at the time.
- A library creates a contract for its users. Compatibility, documentation and behavior need consideration before an API changes.
- Operations that skip validations or delete hierarchies need explicit usage criteria. A gem does not replace application authorization, data integrity or tests.
Implementation
The libraries and the problems they address:
parsecs · coauthor
Equation evaluation in Ruby through a native extension linked to the muparserx-based C++ library.
deep-cloning · coauthor
Deep replication of sets of records and their relationships.
hierarchy-tree · author
Inspection of ActiveRecord class hierarchies and associations.
validations-skipper · author
Selective control over the validations skipped in an operation.
cascade-deleter · author
Deletion of items and their descendants in a hierarchy.
Outcome
All five gems are published and available for anyone assessing my work. They offer concrete examples of Ruby API design, model relationships and reusable responsibilities.