0.0
No commit activity in last 3 years
No release in over 3 years
Provide a simple way of cloning ActiveRecord Records
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.14
>= 0
~> 10.0
~> 3.0
~> 1.3

Runtime

< 6.0, >= 4.0
 Project Readme

QuickClone Build Status Coverage Status Code Climate

Quickly clone an ActiveRecord object by providing a filter of attributes names.

Installation

Add this line to your application's Gemfile:

gem 'quick_clone'

And then execute:

$ bundle

Or install it yourself as:

$ gem install quick_clone

Usage

Provide a simple way of cloning ActiveRecord Records

It will return an in memory object, you will need to save the record yourself.

You supply two things to clone_from method

Clonable.clone_from(original_object, filter)

The above is a convenience method for:

Clonable.new(original_object, filter).clone

  • Original object is just the object where you will copy properties from

  • Filter is an array of properties you want to copy from the original_object you can list the properties as symbols or strings.

If one of the items on that list is a hash, the key has to be the name of the association, the value has to be a list of values that will be copied from all the items of the association.

It handles different association types, belongs_to, has_many, and has_one

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/d3dw/quick_clone.