Class: ActsAsAvatar::SanitizeSvgJob

Inherits:
ActiveJob::Base
  • Object
show all
Includes:
Scrubber
Defined in:
app/jobs/acts_as_avatar/sanitize_svg_job.rb

Instance Method Summary collapse

Methods included from Scrubber

#sanitize

Instance Method Details

#perform(blob) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/jobs/acts_as_avatar/sanitize_svg_job.rb', line 9

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