factorize read_attachment

This commit is contained in:
simon lehericey 2020-12-14 14:08:39 +01:00
parent 38a5847ca4
commit a941626d45

View file

@ -92,20 +92,18 @@ class BillSignature < ApplicationRecord
end end
def read_signature def read_signature
if attachment_changes['signature'] read_attachment('signature')
io = io_for_changes(attachment_changes['signature'])
if io.present?
io.rewind
io.read
end
elsif signature.attached?
signature.download
end
end end
def read_serialized def read_serialized
if attachment_changes['serialized'] read_attachment('serialized')
io = io_for_changes(attachment_changes['serialized']) end
private
def read_attachment(attachment)
if attachment_changes[attachment]
io = io_for_changes(attachment_changes[attachment])
if io.present? if io.present?
io.rewind io.rewind
io.read io.read
@ -115,8 +113,6 @@ class BillSignature < ApplicationRecord
end end
end end
private
def io_for_changes(attachment_changes) def io_for_changes(attachment_changes)
attachable = attachment_changes.attachable attachable = attachment_changes.attachable
case attachable case attachable