Class: Hyrax::VirusScanner
- Inherits:
-
Object
- Object
- Hyrax::VirusScanner
- Defined in:
- app/models/hyrax/virus_scanner.rb
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
Override this method to use your own virus checking software.
-
#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.
27 28 29 |
# File 'app/models/hyrax/virus_scanner.rb', line 27 def initialize(file) @file = file end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
19 20 21 |
# File 'app/models/hyrax/virus_scanner.rb', line 19 def file @file end |
Class Method Details
.infected?(file) ⇒ Boolean
23 24 25 |
# File 'app/models/hyrax/virus_scanner.rb', line 23 def self.infected?(file) new(file).infected? end |
Instance Method Details
#clam_av_scanner ⇒ Object
37 38 39 40 41 42 |
# File 'app/models/hyrax/virus_scanner.rb', line 37 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
Override this method to use your own virus checking software
33 34 35 |
# File 'app/models/hyrax/virus_scanner.rb', line 33 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.
46 47 48 49 50 |
# File 'app/models/hyrax/virus_scanner.rb', line 46 def null_scanner warning "Unable to check #{file} for viruses because no virus scanner is defined" unless Rails.env.test? false end |