Class: AgentClientProtocol::Transport::NdjsonReader
- Inherits:
-
Object
- Object
- AgentClientProtocol::Transport::NdjsonReader
- Defined in:
- lib/agent_client_protocol/transport.rb
Instance Method Summary collapse
- #close ⇒ Object
- #each ⇒ Object
-
#initialize(io, max_line_bytes: MAX_LINE_BYTES) ⇒ NdjsonReader
constructor
A new instance of NdjsonReader.
Constructor Details
#initialize(io, max_line_bytes: MAX_LINE_BYTES) ⇒ NdjsonReader
Returns a new instance of NdjsonReader.
32 33 34 35 |
# File 'lib/agent_client_protocol/transport.rb', line 32 def initialize(io, max_line_bytes: MAX_LINE_BYTES) @io = io @max_line_bytes = max_line_bytes end |
Instance Method Details
#close ⇒ Object
55 56 57 58 59 |
# File 'lib/agent_client_protocol/transport.rb', line 55 def close @io.close unless @io.closed? rescue IOError # already closed end |
#each ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/agent_client_protocol/transport.rb', line 37 def each return enum_for(:each) unless block_given? loop do line = read_line break if line.nil? line = line.strip next if line.empty? begin yield JSON.parse(line) rescue JSON::ParserError => e raise AgentClientProtocol::RequestError.parse_error(e.) end end end |