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