Class: Eye::Client
Instance Attribute Summary collapse
-
#socket_path ⇒ Object
readonly
Returns the value of attribute socket_path.
Instance Method Summary collapse
- #attempt_command(pack) ⇒ Object
- #command(cmd, *args) ⇒ Object
-
#initialize(socket_path) ⇒ Client
constructor
A new instance of Client.
- #send_request(pack) ⇒ Object
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_path ⇒ Object (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 |