Sha256: 21dd0fdf6c701e614739658d2402006c29cf7c5adc78f5a49e24dcdd3150b3a5

Contents?: true

Size: 872 Bytes

Versions: 1

Compression:

Stored size: 872 Bytes

Contents

class VirusScan < ActiveRecord::Base
  TokenNotSpecified = Class.new(StandardError)

  class << self
    attr_writer :token

    def token
      @token || raise(TokenNotSpecified)
    end
  end

  belongs_to :resource, polymorphic: true
  scope :not_scanned, -> { where scan_result: nil }
  validates_inclusion_of :scan_result, in: WitchDoctor::Antivirus::RESULTS, allow_nil: true

  before_update :set_scanned_at, if: :scan_updated?

  def as_json(options={})
    attributes
      .slice('id', 'scan_result', 'scanned_at')
      .tap { |hash|
        hash.merge!('file_url' => file_url)
      }
  end

  # S3 will give url, file wil show mount point, we care just about s3
  def file_url
    resource.send(mount_point).url
  end

  def set_scanned_at
    self.scanned_at = Time.now
  end

  def scan_updated?
    scan_result.in? WitchDoctor::Antivirus::RESULTS
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
witch_doctor-0.1.0 app/models/virus_scan.rb