A Ruby library for defining attributes with type coercion, default values, and embedded objects on plain Ruby objects.
Virtus is a Ruby library that adds attribute definitions with type coercion and default values to plain Ruby objects. It solves the problem of manually handling data conversion and validation by allowing developers to define typed attributes that automatically coerce input values, such as converting strings to integers or hashes to nested objects. This makes it easier to work with external data sources like web parameters or JSON APIs.
Ruby developers building applications that require structured data handling, such as web APIs, domain models, or value objects, especially those needing type-safe attribute assignment and coercion.
Developers choose Virtus for its simplicity and flexibility in adding attribute management to any Ruby object without the overhead of a full ORM. Its support for embedded objects, collections, and custom coercions provides a powerful yet lightweight solution for data mapping and validation.
[DISCONTINUED ] Attributes on Steroids for Plain Old Ruby Objects
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Allows defining typed attributes on classes, modules, or instances with options like private writers, as shown in examples for User and Address classes.
Automatically converts inputs like strings to integers or hashes to nested objects, supporting many coercions including custom ones via Virtus::Attribute subclasses.
Handles complex nested structures with automatic coercion, making it ideal for JSON mapping, as demonstrated with City and Address embedded values.
Supports static values, procs, or method names for defaults, with lazy loading options for dynamic instances.
The author explicitly marks it as discontinued, recommending dry-rb gems as successors, so it lacks updates and community support.
As noted in the README, coercions don't apply when mutating collections after assignment (e.g., using <<), requiring manual workarounds like custom collection classes.
Susceptible to issues with global Boolean constants, forcing workarounds like using Axiom::Types::Boolean, which adds complexity.
Focuses on coercion without built-in validation, so additional gems or custom logic are needed for comprehensive data integrity.