Class: Eye::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(socket_path) ⇒ Client

Returns a new instance of Client.



8
9
10
# File 'lib/eye/client.rb', line 8

def initialize(socket_path)
  @socket_path = socket_path
end

Instance Attribute Details

#socket_pathObject (readonly)

Returns the value of attribute socket_path.



6
7
8
# File 'lib/eye/client.rb', line 6

def socket_path
  @socket_path
end

Instance Method Details

#attempt_command(pack) ⇒ Object



16
17
18
19
20
# File 'lib/eye/client.rb', line 16

def attempt_command(pack)
  Timeout.timeout(Eye::Local.client_timeout) { send_request(pack) }
rescue Timeout::Error, EOFError
  :timeouted
end

#command(cmd, *args) ⇒ Object



12
13
14
# File 'lib/eye/client.rb', line 12

def command(cmd, *args)
  attempt_command(Marshal.dump([cmd, *args]))
end

#send_request(pack) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/eye/client.rb', line 22

def send_request(pack)
  UNIXSocket.open(@socket_path) do |socket|
    socket.write(pack)
    data = socket.read
    Marshal.load(data) rescue :corrupted_data
  end
end