factorize read_attachment
This commit is contained in:
parent
38a5847ca4
commit
a941626d45
1 changed files with 9 additions and 13 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue