Coder Social home page Coder Social logo

victorcorcos / deep-cloning-ruby Goto Github PK

View Code? Open in Web Editor NEW

This project forked from niltonvasques/deep-cloning-ruby

2.0 1.0 0.0 32 KB

DeepCloning is a gem that is able to replicate a set of records in depth

License: Apache License 2.0

Ruby 100.00%

deep-cloning-ruby's Introduction

Deep Cloning Logo

Deep Cloning

Replicate Ruby on Rails Database Hierarchies with Precision

Welcome to Deep Cloning, a powerful Ruby on Rails gem designed to replicate your database hierarchies seamlessly. Whether you're dealing with complex data structures or intricate relationships between models, Deep Cloning ensures that every aspect of your database is accurately reproduced, maintaining model attributes and associations.

Table of Contents

Introduction

Modern applications often require the ability to create copies of database hierarchies while preserving the integrity of the data. Deep Cloning provides a robust solution for Ruby on Rails applications, allowing you to trigger precise replication of database records starting from a specified model, all the way down its associations.

Key Features

  • Model Attributes Preservation: Deep Cloning retains all values for database columns (model attributes), ensuring data fidelity throughout the replication process.

  • Association Cloning: Replicate complex hierarchies effortlessly, preserving relationships between models, just like the original.

  • Customizable Cloning: Tailor the cloning process to meet your specific needs with customizable options and configurations.

  • Efficiency and Performance: Deep Cloning is optimized for speed and efficiency, making it suitable for both small-scale projects and enterprise-level applications.

How to Use

  1. Installation: Add the Deep Cloning gem to your Rails project by including it in your Gemfile and running bundle install.
gem 'deep-cloning'
  1. Trigger Cloning: To replicate a model and its associations, simply call the DeepCloning::Clone.new(@root_item, opts).replicate method on the desired model instance root item.
# @root_item should be already created and is the item to be copied
# @target_item should be already created and is the item which will receive the @root_item hierarchy children to be copied

DeepCloning::Clone.new(@root_item, opts).replicate do |source, destiny, moment|
  case moment
  when :before_save
    before_save(source, destiny)
  when :after_save
    after_save(source, destiny)
  when :skip?
    skip?(source)
  else
    destiny
  end
end

# Clone options
def opts
  {
    # Which classes do you want to copy on the hierarchy?
    including: %w[Project User City],

    # This is necessary: the id of the @root_item should point to the @target_item.
    'RootClass' => { @root_item.id => @target_item },

    # Do you want to save the root model instance?
    save_root: false
  }
end

# You can set up specific handling on the source/destiny item beforing replicating the item
def before_save(source, destiny)
  case source
  when SpecificModel
    # Do specific handlings
  end
end

# You can set up specific handling on the source/destiny item after replicating the item
def after_save(source, destiny)
  case source
  when SpecificModel
    # Do specific handlings
  end
end

# Do you want to skip the copy of an item based on a criteria?
def skip?(source)
  return true if source.is_a? User and source.age > 50
  false
end
  1. Enjoy Precision Replication: Your new project and its associated records are now accurately cloned, ready for use.

Benefits for Large Companies

  • Streamlined Data Management: Deep Cloning simplifies the process of replicating complex database hierarchies, saving valuable time and resources for large-scale projects.

  • Data Privacy and Security: Replicate data within your secure environment, minimizing the need for external tools or services.

  • Efficient Testing and Development: Expedite development and testing processes by creating comprehensive test datasets and prototypes with ease.

  • Enhanced Productivity: Maximize efficiency by rapidly setting up new projects with data structures mirroring existing successful ones.

Get Started

Explore the potential of Deep Cloning by incorporating it into your Ruby on Rails projects. Clone with precision, maintain data integrity, and elevate your development workflow. Check out the official documentation and get started today!

For any inquiries or collaboration opportunities, feel free to reach out to the repository creators.

Contact

  1. Victor Cordeiro Costa
  2. Nilton Vasques

*This repository is maintained and developed by Victor Cordeiro Costa and Nilton Vasques. For inquiries, partnerships, or support, please contact us.

deep-cloning-ruby's People

Contributors

niltonvasques avatar victorcorcos avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.