noesya/osuny

View on GitHub
app/models/communication/website/with_screenshot.rb

Summary

Maintainability
A
0 mins
Test Coverage
F
50%
module Communication::Website::WithScreenshot
  extend ActiveSupport::Concern
  
  included do
    has_one_attached :screenshot
  end
  
  def screenshot!
    return if url.blank?
    screenshot_url = Screenshot.capture(url)
    return if screenshot_url.blank?
    downloaded_image = URI(screenshot_url).open
    self.screenshot.attach  io: downloaded_image, 
                            filename: "screenshot.png"
  end
end