Class: ActiveStorageSvgSanitizer::SanitizeSvgJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/active_storage_svg_sanitizer/sanitize_svg_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(blob) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/jobs/active_storage_svg_sanitizer/sanitize_svg_job.rb', line 5

def perform(blob)
  return unless blob.svg?
  return if blob.[:sanitized]

  sanitized = sanitize(blob.download)
  Tempfile.open([blob.filename.base, blob.filename.extension]) do |file|
    file.print sanitized
    file.rewind
    blob.upload file
  end

  blob.[:sanitized] = true
  blob.save
end