A Ruby gem that adds deep cloning capabilities to ActiveRecord models, including user-specified associations.
Deep Cloneable is a Ruby gem that adds a `deep_clone` method to ActiveRecord models, allowing developers to create deep copies of database records along with their associated records. It solves the problem of duplicating complex object graphs in Rails applications, where simple duplication methods only copy the base model without its relationships.
Ruby on Rails developers who need to clone ActiveRecord models with their associations, such as when implementing copy functionality for nested resources or duplicating complex data structures.
Developers choose Deep Cloneable because it provides a comprehensive and flexible solution for deep cloning ActiveRecord objects, with support for nested associations, attribute control, and handling of file attachments, all while maintaining performance with features like validation skipping and dictionary-based object reuse.
This gem gives every ActiveRecord::Base object the possibility to do a deep clone that includes user specified associations.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Supports single, multiple, and deeply nested includes with conditional logic (e.g., `if`/`unless` lambdas), allowing precise control over what gets cloned from the README examples.
Provides `except` and `only` options for excluding or including specific attributes during cloning, enabling fine-grained data duplication as shown in the usage section.
Includes a dictionary feature that prevents duplicate cloning of the same object across nested associations, improving performance and consistency in complex graphs.
Offers documented examples for cloning models with CarrierWave, Shrine, and ActiveStorage attachments, though manual setup is required for each case.
For file attachments with CarrierWave, Shrine, or ActiveStorage, developers must write additional code in blocks or processors, which is error-prone and not automated.
Upgrading from v2 to v3 introduced breaking changes like altered block evaluation order and exception class names, requiring code updates as noted in the README.
Limited to ActiveRecord models; it cannot clone non-ActiveRecord objects or work with other ORMs, reducing flexibility in mixed-technology stacks.