Class: Del::SocketMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/del/socket_message.rb

Instance Method Summary collapse

Constructor Details

#initialize(shell, socket_file:) ⇒ SocketMessage

Returns a new instance of SocketMessage.



5
6
7
8
# File 'lib/del/socket_message.rb', line 5

def initialize(shell, socket_file:)
  @shell = shell
  @socket_file = socket_file
end

Instance Method Details

#closeObject



23
24
25
# File 'lib/del/socket_message.rb', line 23

def close
  socket&.close
end

#deliver(payload) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/del/socket_message.rb', line 10

def deliver(payload)
  socket.puts(message_for(payload))
rescue EOFError => error
  @shell.say error.message, :red
rescue Errno::ECONNREFUSED => error
  @shell.say error.message, :red
  @shell.say 'You must start the del server first.', :yellow
end

#listenObject



19
20
21
# File 'lib/del/socket_message.rb', line 19

def listen
  socket.readline
end