0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
A library that lets you clone objects and object graphs
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.10.6
~> 0.10.6
~> 1.4
>= 0
~> 1.2.9

Runtime

~> 1.2.0
 Project Readme

Datamapper deep cloning extention

This DataMapper extension adds deep cloning functionality to your resource objects. You can use it to recursively clone objects following spefic relations which need to be specified explicitly.

Usage

Given the following models:

class Blog
  has n, :posts
end

class Post
  belongs_to :blog
end   

Cloning a blog including all its posts would look like:

new_blog = blog.deep_clone(:posts)

This would initialize a new Blog object with all attrbutes taken from the original blog. new_blog.posts would consist of (unsaved) clones of the original entrys from blog.posts.

If you don't want just to initialize the clones but to create them to, use :create as first parameter:

new_blog = blog.deep_clone(:create, :posts)

Nested recursion

Given a further model Comment:

class Comment
  belongs_to :post
end

Post.has n, :comments

You can also specify nested parameters like:

blog.deep_clone(:posts => :comments)

It's also possible to spcify Arrays of relation names.