Class: ClamAV::Client
- Inherits:
-
Object
- Object
- ClamAV::Client
- Defined in:
- lib/clamav/client.rb
Instance Method Summary collapse
- #default_connection ⇒ Object
- #execute(command) ⇒ Object
-
#initialize(connection = default_connection) ⇒ Client
constructor
A new instance of Client.
- #ping ⇒ Object
- #resolve_default_socket ⇒ Object
- #safe?(target) ⇒ Boolean
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_connection ⇒ Object
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 |
#ping ⇒ Object
53 54 55 |
# File 'lib/clamav/client.rb', line 53 def ping execute Commands::PingCommand.new end |
#resolve_default_socket ⇒ Object
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
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 |