Class: WitchDoctor::Antivirus

Inherits:
Object
  • Object
show all
Defined in:
lib/witch_doctor/antivirus.rb

Constant Summary collapse

RESULTS =
['Clean', 'VirusInfected', 'FileDownloadError']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, mount_point) ⇒ Antivirus

Returns a new instance of Antivirus.



6
7
8
9
# File 'lib/witch_doctor/antivirus.rb', line 6

def initialize(resource, mount_point)
  @resource = resource
  @mount_point = mount_point.to_s
end

Instance Attribute Details

#mount_pointObject (readonly)

Returns the value of attribute mount_point.



4
5
6
# File 'lib/witch_doctor/antivirus.rb', line 4

def mount_point
  @mount_point
end

#resourceObject (readonly)

Returns the value of attribute resource.



4
5
6
# File 'lib/witch_doctor/antivirus.rb', line 4

def resource
  @resource
end

Instance Method Details

#checked?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/witch_doctor/antivirus.rb', line 22

def checked?
  scheduled? && latest_scan.scan_result.present?
end

#clean?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/witch_doctor/antivirus.rb', line 34

def clean?
  checked? && latest_scan.scan_result == 'Clean'
end

#error?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/witch_doctor/antivirus.rb', line 30

def error?
  checked? && latest_scan.scan_result == 'FileDownloadError'
end

#infected?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/witch_doctor/antivirus.rb', line 26

def infected?
  checked? && latest_scan.scan_result == 'VirusInfected'
end

#latest_scanObject



11
12
13
14
15
16
# File 'lib/witch_doctor/antivirus.rb', line 11

def latest_scan
  @latest_scan ||= resource
    .virus_scans
    .select { |vs| vs.mount_point == mount_point }
    .last
end

#scheduled?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/witch_doctor/antivirus.rb', line 18

def scheduled?
  !latest_scan.nil?
end