Method: ActiveRecord::Acts::Versioned::ActMethods#clone_versioned_model

Defined in:
lib/junebug/ext/acts_as_versioned.rb

#clone_versioned_model(orig_model, new_model) ⇒ Object

Clones a model. Used when saving a new version or reverting a model’s version.



329
330
331
332
333
334
335
336
337
338
339
# File 'lib/junebug/ext/acts_as_versioned.rb', line 329

def clone_versioned_model(orig_model, new_model)
  self.versioned_attributes.each do |key|
    new_model.send("#{key}=", orig_model.attributes[key]) if orig_model.has_attribute?(key)
  end
  
  if orig_model.is_a?(self.class.versioned_class)
    new_model[new_model.class.inheritance_column] = orig_model[self.class.versioned_inheritance_column]
  elsif new_model.is_a?(self.class.versioned_class)
    new_model[self.class.versioned_inheritance_column] = orig_model[orig_model.class.inheritance_column]
  end
end