Class: Hyrax::VirusCheckerService

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/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 = Hyrax.config.virus_scanner) ⇒ VirusCheckerService

Returns a new instance of VirusCheckerService.



15
16
17
18
# File 'app/services/hyrax/virus_checker_service.rb', line 15

def initialize(original_file, system_virus_scanner = Hyrax.config.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.



6
7
8
# File 'app/services/hyrax/virus_checker_service.rb', line 6

def original_file
  @original_file
end

#system_virus_scannerObject

Returns the value of attribute system_virus_scanner.



6
7
8
# File 'app/services/hyrax/virus_checker_service.rb', line 6

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



11
12
13
# File 'app/services/hyrax/virus_checker_service.rb', line 11

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)


21
22
23
24
# File 'app/services/hyrax/virus_checker_service.rb', line 21

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