I'm trying to build inheritance in my app .
In fact it's simple i have several models , and some of them need to be 'archive' , it simply means that i gonna move data from my database public schemat to an archive schemat ( same database ).
Each models have a methods 'save'itself'OnArchive by example :
def saveContactArchive(contact)
record = ArchContacts.new
record.id=contact.id
record.information_id=contact.information_id
record.is_internal = contact.is_internal if (contact.is_internal != nil)
record.type_contact_id = contact.type_contact_id if (contact.type_contact_id != nil)
record.user_id = contact.user_id if (contact.user_id != nil)
record.info_readed = contact.info_readed if (contact.info_readed != nil)
record.not_received = contact.not_received if (contact.not_received != nil)
record.society_name = contact.society_name if (contact.society_name != nil)
record.person_name = contact.person_name if (contact.person_name != nil)
record.email = contact.email if (contact.email != nil)
record.receipt = contact.receipt if (contact.receipt != nil)
record.receipt_confirmed = contact.receipt_confirmed if (contact.receipt_confirmed != nil)
record.created_at = contact.created_at if (contact.created_at != nil)
record.updated_at = contact.updated_at if (contact.updated_at != nil)
id = contact.id
if (!existOnArchive(id))
return record.save
else
return true
end
end
And SOME of models have a methodes save'arrayOf'OnArchive by example :
def saveContactsArchive(contacts)
resultContact = false
for c in contacts
if(c.id != nil)
resultContact = saveContactArchive(c)
else
resultContact = true
end
if(!resultContact)
ArchiveLogs.debug("Sauvegarde d'un contact sur l archive echoue, contact concerne "+c.inspect)
end
end
return resultContact
end
I'm trying to create a parent class for all those Models , called Archive. This class woud define 2 methods
class Archive
def saveOnArchive(element)
"Save on archive"
end
def saveArrayOnArchive(elements)
"Save an array on archive"
end
end
saveArrayOnArchive follow the same logic for all models , like for saveContactsArchive ; loop on array , for each element call saveOnArchive, write logs if error .
My questions ;
1)is that better to create a modular saveArrayOnArchive and how to call children method saveOnArchive from parent class?
2)What my models gonna look like ? have they to redifine every methods ? calling super if they don't add anything to parent method?
3)is that even possible since my models are already childreen from activerecord class ArchContacts < ActiveRecord::Base ----EDIT---- Why shoud my models be children of ActiveRecord::Base (i just followed an other dev model without brain ....) ----EDIT----
3 in 1 ) How to achieve this if someone understood me ... any help apricieted