Module: Hydra::MessagingIO
Overview
Module that implemets methods that auto-serialize and deserialize messaging objects.
Defined Under Namespace
Classes: UnprocessableMessage
Instance Method Summary collapse
-
#close ⇒ Object
Closes the IO object.
-
#gets ⇒ Object
Read a Message from the input IO object.
-
#write(message) ⇒ Object
Write a Message to the output IO object.
Instance Method Details
#close ⇒ Object
Closes the IO object.
36 37 38 39 |
# File 'lib/hydra/messaging_io.rb', line 36 def close @reader.close if @reader @writer.close if @writer end |
#gets ⇒ Object
Read a Message from the input IO object. Automatically build a message from the response and return it.
IO.gets
=> Hydra::Message # or subclass
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hydra/messaging_io.rb', line 10 def gets while true begin raise IOError unless @reader = @reader.gets return nil unless return Message.build(eval(.chomp)) rescue SyntaxError, NameError # uncomment to help catch remote errors by seeing all traffic #$stderr.write "Not a message: [#{message.inspect}]\n" end end end |
#write(message) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/hydra/messaging_io.rb', line 27 def write() raise IOError unless @writer raise UnprocessableMessage unless .is_a?(Hydra::Message) @writer.write(.serialize+"\n") rescue Errno::EPIPE raise IOError end |