witch_doctor 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b90d201e964e217789d40cb46ece7c0cac3e62e6
4
- data.tar.gz: 3fb22f847c9fe7a42e8d2e7d0e89aab3c912b7d1
3
+ metadata.gz: 0a68de9c0229908f16ef56db5233f76fc4ec7759
4
+ data.tar.gz: c181046a0c33f9284bba71b7958f8fd05f94e9a4
5
5
  SHA512:
6
- metadata.gz: af212a673286818932bbd24897c9de1cfe53443923fd64ae07c470492d278b35fc7b0265cd9eed716a9521fc664783a5baf66abe538aaad498609d875b369216
7
- data.tar.gz: 0000d5200b7c430f40432b66061c013e628197bace0d721699f8ae206ee81aee2cdef64fce786a66abcdd78d0ba157571b77367bf72675d2e5a28721afe7eb3a
6
+ metadata.gz: 27093f9bec95fb4a47e6d51ff70afad73fc0a1100d80f70f02e52982efccf413c875fd37b0d06b6fa3dfcaee544b5cd00e1392b237b6a171253e3621f4f3addc
7
+ data.tar.gz: 6953f75161977291f1ca2226a49f795fbb5b4ec6d2bf74caefd5af42187cd72dd56a4f689976dfeba9fd26ca7849e19790690e788371096b15111f18b7626780
@@ -1,15 +1,21 @@
1
1
  module WitchDoctor
2
2
  module ApplicationHelper
3
+ UnknownAntivirusScanState = Class.new(StandardError)
4
+
3
5
  def antivirus(resource, mount_point)
4
6
  av = resource.send("#{mount_point}_antivirus")
5
- if !av.checked?
7
+ if !av.scheduled?
8
+ 'Antivirus scan has not been scheduled<br>'.html_safe
9
+ elsif !av.checked?
6
10
  'File waiting for Antivirus check<br>'.html_safe
7
11
  elsif av.clean?
8
12
  yield
9
13
  elsif av.error?
10
14
  "Antivirus scan couldn't be completed<br>".html_safe
11
- else
15
+ elsif av.infected?
12
16
  'File Contains Virus<br>'.html_safe
17
+ else
18
+ raise UnknownAntivirusScanState
13
19
  end
14
20
  end
15
21
  end
@@ -9,18 +9,22 @@ module WitchDoctor
9
9
  end
10
10
 
11
11
  def latest_scan
12
- resource
12
+ @latest_scan ||= resource
13
13
  .virus_scans
14
14
  .select { |vs| vs.mount_point == mount_point }
15
15
  .last
16
16
  end
17
17
 
18
+ def scheduled?
19
+ !latest_scan.nil?
20
+ end
21
+
18
22
  def checked?
19
- latest_scan.scan_result.present?
23
+ scheduled? && latest_scan.scan_result.present?
20
24
  end
21
25
 
22
26
  def infected?
23
- checked? && !clean? && !error?
27
+ checked? && latest_scan.scan_result == 'VirusInfected'
24
28
  end
25
29
 
26
30
  def error?
@@ -14,7 +14,7 @@ module WitchDoctor
14
14
  def schedule_virus_scan(options)
15
15
  mount_point = options.fetch(:on)
16
16
 
17
- after_save "schedule_#{mount_point}_virus_scan", if: "schedule_#{mount_point}_virus_scan?"
17
+ after_save "schedule_#{mount_point}_virus_scan", if: ["schedule_#{mount_point}_virus_scan?", :virus_scan_scheduling_on?]
18
18
  after_destroy "unschedule_#{mount_point}_virus_scan"
19
19
 
20
20
  define_method("unschedule_#{mount_point}_virus_scan") do
@@ -24,12 +24,6 @@ module WitchDoctor
24
24
  define_method("schedule_#{mount_point}_virus_scan") do
25
25
  virus_scans.create! do |vs|
26
26
  vs.mount_point = mount_point.to_s
27
- # This is especially useful for integration testing, since your application may
28
- # make assumptions (e.g. in the views) about the existence of a virus scan
29
- unless virus_scan_scheduling_on?
30
- vs.scan_result = 'Clean'
31
- vs.scanned_at = Time.now
32
- end
33
27
  end
34
28
  end
35
29
 
@@ -1,3 +1,3 @@
1
1
  module WitchDoctor
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end