fixup! tech(refactor): extract clone logic inside its own class
This commit is contained in:
parent
32e8f34511
commit
2200310877
1 changed files with 16 additions and 12 deletions
|
@ -2,25 +2,29 @@ class ClonePiecesJustificativesService
|
|||
def self.clone_attachments(original, kopy)
|
||||
case original
|
||||
when Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp
|
||||
original.piece_justificative_file.attachments.each do |attachment|
|
||||
kopy.piece_justificative_file.attach(attachment.blob)
|
||||
end
|
||||
clone_many_attachments(original, kopy, :piece_justificative_file)
|
||||
when TypeDeChamp
|
||||
clone_attachment(original, kopy, :piece_justificative_template)
|
||||
clone_one_attachment(original, kopy, :piece_justificative_template)
|
||||
when Procedure
|
||||
clone_attachment(original, kopy, :logo)
|
||||
clone_attachment(original, kopy, :notice)
|
||||
clone_attachment(original, kopy, :deliberation)
|
||||
clone_one_attachment(original, kopy, :logo)
|
||||
clone_one_attachment(original, kopy, :notice)
|
||||
clone_one_attachment(original, kopy, :deliberation)
|
||||
when AttestationTemplate
|
||||
clone_attachment(original, kopy, :logo)
|
||||
clone_attachment(original, kopy, :signature)
|
||||
clone_one_attachment(original, kopy, :logo)
|
||||
clone_one_attachment(original, kopy, :signature)
|
||||
when Etablissement
|
||||
clone_attachment(original, kopy, :entreprise_attestation_sociale)
|
||||
clone_attachment(original, kopy, :entreprise_attestation_fiscale)
|
||||
clone_one_attachment(original, kopy, :entreprise_attestation_sociale)
|
||||
clone_one_attachment(original, kopy, :entreprise_attestation_fiscale)
|
||||
end
|
||||
end
|
||||
|
||||
def self.clone_attachment(original, kopy, attachment_name)
|
||||
def self.clone_many_attachments(original, kopy, attachments_name)
|
||||
original.public_send(attachments_name).attachments.each do |attachment|
|
||||
kopy.public_send(attachments_name).attach(attachment.blob)
|
||||
end
|
||||
end
|
||||
|
||||
def self.clone_one_attachment(original, kopy, attachment_name)
|
||||
attachment = original.public_send(attachment_name)
|
||||
if attachment.attached?
|
||||
kopy.public_send(attachment_name).attach(attachment.blob)
|
||||
|
|
Loading…
Reference in a new issue