Class: Hydra::Works::VirusCheckerService

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

Overview

Responsible for checking if the given file is a virus. Coordinates with the underlying system virus scanner.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_file, system_virus_scanner = Hydra::Works.default_system_virus_scanner) ⇒ VirusCheckerService

Returns a new instance of VirusCheckerService.



14
15
16
17
# File 'lib/hydra/works/services/virus_checker_service.rb', line 14

def initialize(original_file, system_virus_scanner = Hydra::Works.default_system_virus_scanner)
  self.original_file = original_file
  self.system_virus_scanner = system_virus_scanner
end

Instance Attribute Details

#original_fileObject

Returns the value of attribute original_file.



5
6
7
# File 'lib/hydra/works/services/virus_checker_service.rb', line 5

def original_file
  @original_file
end

#system_virus_scannerObject

Returns the value of attribute system_virus_scanner.



5
6
7
# File 'lib/hydra/works/services/virus_checker_service.rb', line 5

def system_virus_scanner
  @system_virus_scanner
end

Class Method Details

.file_has_virus?(original_file) ⇒ Boolean

Returns true or false result from system_virus_scanner.

Parameters:

  • original_file (String, #path)

Returns:

  • (Boolean)

    true or false result from system_virus_scanner



10
11
12
# File 'lib/hydra/works/services/virus_checker_service.rb', line 10

def self.file_has_virus?(original_file)
  new(original_file).file_has_virus?
end

Instance Method Details

#file_has_virus?Boolean

Default behavior is to raise a validation error and halt the save if a virus is found

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/hydra/works/services/virus_checker_service.rb', line 20

def file_has_virus?
  path = original_file.is_a?(String) ? original_file : local_path_for_file(original_file)
  system_virus_scanner.infected?(path)
end