Class: ZMQMachine::LogServer

Inherits:
Object
  • Object
show all
Includes:
Server::SUB
Defined in:
lib/zm/log_server.rb

Instance Method Summary collapse

Methods included from Server::Base

#on_attach, #on_readable, #on_readable_error, #on_writable, #on_writable_error, #shutdown

Constructor Details

#initialize(configuration) ⇒ LogServer

Returns a new instance of LogServer.



42
43
44
45
46
47
# File 'lib/zm/log_server.rb', line 42

def initialize(configuration)
  configuration.on_read = method(:on_read)
  super

  @file = configuration.extra[:file] || STDOUT
end

Instance Method Details

#on_read(socket, messages) ⇒ Object

Writes all messages to the file.



51
52
53
54
55
56
57
58
59
60
# File 'lib/zm/log_server.rb', line 51

def on_read socket, messages
  string = ''
  messages.each_with_index do |message, index|
    string << '|' if index > 0
    string << "#{message.copy_out_string}"
  end

  @file.print "#{string}\n"
  @file.flush
end

#write(messages) ⇒ Object



62
63
64
# File 'lib/zm/log_server.rb', line 62

def write messages
  # no op
end