Module: Clamby

Defined in:
lib/clamby.rb,
lib/clamby/error.rb,
lib/clamby/command.rb,
lib/clamby/version.rb

Defined Under Namespace

Classes: ClamscanClientError, ClamscanMissing, Command, Error, FileNotFound, VirusDetected

Constant Summary collapse

DEFAULT_CONFIG =
{
  :check => true,
  :daemonize => false,
  :config_file => nil,
  :error_clamscan_missing => true,
  :error_clamscan_client_error => false,
  :error_file_missing => true,
  :error_file_virus => false,
  :fdpass => false,
  :stream => false,
  :output_level => 'medium',
  :executable_path_clamscan => 'clamscan',
  :executable_path_clamdscan => 'clamdscan',
  :executable_path_freshclam => 'freshclam',
}.freeze
VERSION =
"1.5.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject (readonly)

Returns the value of attribute config.



28
29
30
# File 'lib/clamby.rb', line 28

def config
  @config
end

.valid_config_keysObject (readonly)

Returns the value of attribute valid_config_keys.



29
30
31
# File 'lib/clamby.rb', line 29

def valid_config_keys
  @valid_config_keys
end

Class Method Details

.configure(opts = {}) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/clamby.rb', line 32

def self.configure(opts = {})
  if opts.delete(:silence_output)
    warn ':silence_output config is deprecated. Use :output_level => "off" instead.'
    opts[:output_level] = 'off'
  end

  opts.each {|k,v| config[k.to_sym] = v if valid_config_keys.include? k.to_sym}
end

.daemonize?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/clamby.rb', line 66

def self.daemonize?
  !! config[:daemonize]
end

.safe?(path) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
45
# File 'lib/clamby.rb', line 41

def self.safe?(path)
  value = virus?(path)
  return nil if value.nil?
  ! value
end

.scanner_exists?Boolean

Returns:

  • (Boolean)

Raises:



52
53
54
55
56
57
58
59
60
# File 'lib/clamby.rb', line 52

def self.scanner_exists?
  return true unless config[:check]
  scanner = Command.clamscan_version

  return true if scanner
  return false unless config[:error_clamscan_missing]

  raise Clamby::ClamscanMissing.new("#{Command.scan_executable} not found. Check your installation and path.")
end

.updateObject



62
63
64
# File 'lib/clamby.rb', line 62

def self.update
  Command.freshclam
end

.virus?(path) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
# File 'lib/clamby.rb', line 47

def self.virus?(path)
  return nil unless scanner_exists?
  Command.scan path
end