Class: FormAttachment

Inherits:
ApplicationRecord show all
Includes:
SentryLogging, SetGuid
Defined in:
app/models/form_attachment.rb

Instance Method Summary collapse

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger

Methods inherited from ApplicationRecord

descendants_using_encryption, lockbox_options, #timestamp_attributes_for_update_in_model, #valid?

Instance Method Details

#get_fileObject



28
29
30
31
32
33
34
# File 'app/models/form_attachment.rb', line 28

def get_file
  attachment_uploader = get_attachment_uploader
  attachment_uploader.retrieve_from_store!(
    parsed_file_data['filename']
  )
  attachment_uploader.file
end

#parsed_file_dataObject



24
25
26
# File 'app/models/form_attachment.rb', line 24

def parsed_file_data
  @parsed_file_data ||= JSON.parse(file_data)
end

#set_file_data!(file, file_password = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'app/models/form_attachment.rb', line 14

def set_file_data!(file, file_password = nil)
  attachment_uploader = get_attachment_uploader
  file = unlock_pdf(file, file_password) if file_password.present?
  attachment_uploader.store!(file)
  self.file_data = { filename: attachment_uploader.filename }.to_json
rescue CarrierWave::IntegrityError => e
  log_exception_to_sentry(e, nil, nil, 'warn')
  raise Common::Exceptions::UnprocessableEntity.new(detail: e.message, source: 'FormAttachment.set_file_data')
end