Class: Hydra::Works::VirusScanner

Inherits:
Object
  • Object
show all
Defined in:
lib/hydra/works/virus_scanner.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ VirusScanner

Returns a new instance of VirusScanner.



26
27
28
# File 'lib/hydra/works/virus_scanner.rb', line 26

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



18
19
20
# File 'lib/hydra/works/virus_scanner.rb', line 18

def file
  @file
end

Class Method Details

.infected?(file) ⇒ Boolean

Parameters:

  • file (String)

Returns:

  • (Boolean)


22
23
24
# File 'lib/hydra/works/virus_scanner.rb', line 22

def self.infected?(file)
  new(file).infected?
end

Instance Method Details

#clam_av_scannerObject



36
37
38
39
40
41
# File 'lib/hydra/works/virus_scanner.rb', line 36

def clam_av_scanner
  scan_result = ClamAV.instance.method(:scanfile).call(file)
  return false if scan_result == 0
  warning "A virus was found in #{file}: #{scan_result}"
  true
end

#infected?Boolean

Override this method to use your own virus checking software

Returns:

  • (Boolean)


32
33
34
# File 'lib/hydra/works/virus_scanner.rb', line 32

def infected?
  defined?(ClamAV) ? clam_av_scanner : null_scanner
end

#null_scannerObject

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.



45
46
47
48
# File 'lib/hydra/works/virus_scanner.rb', line 45

def null_scanner
  warning "Unable to check #{file} for viruses because no virus scanner is defined"
  false
end