Module: CouchCloner::Clone::InstanceMethods
- Defined in:
- lib/couch_cloner/clone.rb
Instance Method Summary collapse
Instance Method Details
#clone(&block) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/couch_cloner/clone.rb', line 9 def clone(&block) verify_clone_preconditions block ||= Proc.new {} property_names = properties.map(&:name) - (protected_properties.map(&:name) + %w{_id _attachments _rev milestone_memories}) attrs = property_names.inject({}){|hash, x| val = send(x) val = val.to_a if val.class == CouchRest::Model::CastedArray hash[x] = val hash } self.class.new(attrs).tap(&block) end |
#clone!(&block) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/couch_cloner/clone.rb', line 24 def clone!(&block) verify_clone_preconditions has_block = !block.nil? block ||= Proc.new {} next_id = database.server.next_uuid copy next_id doc = self.class.get(next_id) has_block ? doc.tap(&block).tap {|d| d.save} : doc end |