Class: SocketListener

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

Instance Method Summary collapse

Constructor Details

#initialize(arguments = []) ⇒ SocketListener

Returns a new instance of SocketListener.



5
6
7
# File 'lib/socket_listener.rb', line 5

def initialize arguments=[]
  read_arguments arguments
end

Instance Method Details

#listenObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/socket_listener.rb', line 8

def listen 
  at_exit { FileUtils.rm SOCKET_FILE }
  server = UNIXServer.new SOCKET_FILE

  loop do
    client = server.accept
    arguments = YAML.load(client.read)
    read_arguments arguments
  end
end

#read_arguments(arguments) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/socket_listener.rb', line 19

def read_arguments arguments 
  arguments.each do |argument| 
    printf("Received message: %s\n", argument)
    daemon if argument == 'daemon'
    quit if argument == 'quit'
  end
end