Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
49 lines (32 sloc) 1.12 KB


Exposes a "Recloner" module containing a "clone" method that you can mixin to your CouchRest::Model::Base derived objects.


$ gem install recloner


There are two types of clones: soft clones (the clone method) and persisted clones (the clone! method).

Soft clones

require 'recloner'
class MyDocument < CouchRest::Model::Base
  include Recloner
  property :name

m = MyDocument.create :name => "m"
p #==> "78439279432743279"
p #==> "m"
m1 = m.clone

m1.new_record? #==> true #==> nil

As you can see, a soft clone simply creates a copy in-memory - it's up to you to persist it (save) to the database.

Persisted clones

m = MyDocument.create :name => "m"
p #==> "78439279432743279"
p #==> "m"
m1 = m.clone!
p #==> "45353762637126371"
p #==> "m"

Modifying your clone

You can pass modifications to the clone (either a soft clone or a persisted clone) in the following manner:

m = MyDocument.create :name => "m"
m1 = m.clone do |doc| += " clone"