Class: Rucoa::MessageReader
- Inherits:
-
Object
- Object
- Rucoa::MessageReader
- Defined in:
- lib/rucoa/message_reader.rb
Instance Method Summary collapse
-
#initialize(io) ⇒ MessageReader
constructor
A new instance of MessageReader.
- #read {|message| ... } ⇒ Enumerator<Hash>, void
Constructor Details
#initialize(io) ⇒ MessageReader
Returns a new instance of MessageReader.
8 9 10 11 |
# File 'lib/rucoa/message_reader.rb', line 8 def initialize(io) @io = io @io.binmode end |
Instance Method Details
#read {|message| ... } ⇒ Enumerator<Hash>, void
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rucoa/message_reader.rb', line 15 def read return enum_for(:read) unless block_given? while (buffer = @io.gets("\r\n\r\n")) content_length = buffer[/Content-Length: (\d+)/i, 1] raise Errors::ContentLengthHeaderNotFound unless content_length body = @io.read(content_length.to_i) raise Errors::ContentLengthHeaderNotFound unless body yield ::JSON.parse(body) end end |