Class: ClamAV::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/clamav/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection = default_connection) ⇒ Client

Returns a new instance of Client.



28
29
30
31
# File 'lib/clamav/client.rb', line 28

def initialize(connection = default_connection)
  @connection = connection
  connection.establish_connection
end

Instance Method Details

#default_connectionObject



37
38
39
40
41
42
# File 'lib/clamav/client.rb', line 37

def default_connection
  ClamAV::Connection.new(
    socket: resolve_default_socket,
    wrapper: ::ClamAV::Wrappers::NewLineWrapper.new
  )
end

#execute(command) ⇒ Object



33
34
35
# File 'lib/clamav/client.rb', line 33

def execute(command)
  command.call(@connection)
end

#pingObject



53
54
55
# File 'lib/clamav/client.rb', line 53

def ping
  execute Commands::PingCommand.new
end

#resolve_default_socketObject



44
45
46
47
48
49
50
51
# File 'lib/clamav/client.rb', line 44

def resolve_default_socket
  unix_socket, tcp_host, tcp_port = ENV.values_at('CLAMD_UNIX_SOCKET', 'CLAMD_TCP_HOST', 'CLAMD_TCP_PORT')
  if tcp_host && tcp_port
    ::TCPSocket.new(tcp_host, tcp_port)
  else
    ::UNIXSocket.new(unix_socket || '/var/run/clamav/clamd.ctl')
  end
end

#safe?(target) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
# File 'lib/clamav/client.rb', line 57

def safe?(target)
  return instream(target).virus_name.nil? if target.is_a?(StringIO)
  scan(target).all? { |file| file.virus_name.nil? }
end