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,
  :reload => false,
  :output_level => 'medium',
  :datadir => nil,
  :executable_path_clamscan => 'clamscan',
  :executable_path_clamdscan => 'clamdscan',
  :executable_path_freshclam => 'freshclam',
}.freeze
VERSION =
"1.6.11"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

.valid_config_keysObject (readonly)

Returns the value of attribute valid_config_keys.



31
32
33
# File 'lib/clamby.rb', line 31

def valid_config_keys
  @valid_config_keys
end

Class Method Details

.configure(opts = {}) ⇒ Object



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

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)


68
69
70
# File 'lib/clamby.rb', line 68

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

.safe?(path) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
# File 'lib/clamby.rb', line 43

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

.scanner_exists?Boolean

Returns:

  • (Boolean)

Raises:



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

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



64
65
66
# File 'lib/clamby.rb', line 64

def self.update
  Command.freshclam
end

.virus?(path) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/clamby.rb', line 49

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