Class: Hyrax::VirusScanner
- Inherits:
-
Object
- Object
- Hyrax::VirusScanner
- Defined in:
- app/models/hyrax/virus_scanner.rb
Overview
The default virus scanner ported from Hyrax::Works
.
If ClamAV is present, it will be used to check for the presence of a virus. If ClamAV is not installed or otherwise not available to your application, Hyrax::Works
does no virus checking add assumes files have no viruses.
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Class Method Summary collapse
Instance Method Summary collapse
- #clam_av_scanner ⇒ Object
- #infected? ⇒ Boolean
-
#initialize(file) ⇒ VirusScanner
constructor
A new instance of VirusScanner.
-
#null_scanner ⇒ Object
Always return zero if there’s nothing available to check for viruses.
Constructor Details
#initialize(file) ⇒ VirusScanner
Returns a new instance of VirusScanner.
32 33 34 |
# File 'app/models/hyrax/virus_scanner.rb', line 32 def initialize(file) @file = file end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
23 24 25 |
# File 'app/models/hyrax/virus_scanner.rb', line 23 def file @file end |
Class Method Details
.infected?(file) ⇒ Boolean
28 29 30 |
# File 'app/models/hyrax/virus_scanner.rb', line 28 def self.infected?(file) new(file).infected? end |
Instance Method Details
#clam_av_scanner ⇒ Object
44 45 46 47 48 49 |
# File 'app/models/hyrax/virus_scanner.rb', line 44 def clam_av_scanner scan_result = ClamAV.instance.method(:scanfile).call(file) return false if scan_result.zero? warning "A virus was found in #{file}: #{scan_result}" true end |
#infected? ⇒ Boolean
Note:
Override this method to use your own virus checking software
40 41 42 |
# File 'app/models/hyrax/virus_scanner.rb', line 40 def infected? defined?(ClamAV) ? clam_av_scanner : null_scanner end |
#null_scanner ⇒ Object
Always return zero if there’s nothing available to check for viruses. This means that we assume all files have no viruses because we can’t conclusively say if they have or not.
55 56 57 58 59 |
# File 'app/models/hyrax/virus_scanner.rb', line 55 def null_scanner warning "Unable to check #{file} for viruses because no virus scanner is defined" unless Rails.env.test? false end |