Module: Recloner
- Defined in:
- lib/recloner/recloner.rb
Instance Method Summary collapse
Instance Method Details
#clone(&block) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 |
# File 'lib/recloner/recloner.rb', line 2 def clone(&block) block ||= Proc.new {} property_names = properties.map(&:name) - protected_properties.map(&:name) 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
14 15 16 17 18 19 |
# File 'lib/recloner/recloner.rb', line 14 def clone!(&block) block ||= Proc.new {} next_id = database.server.next_uuid copy next_id self.class.get(next_id).tap(&block).tap {|d| d.save} end |