Class: Docker::API::Stream::JSONLines

Inherits:
Object
  • Object
show all
Defined in:
lib/docker/api/stream.rb

Overview

Parses the newline-delimited JSON that pull, push, build and /events stream their progress in.

Examples:

lines = Stream::JSONLines.new { |event| puts event["status"] }
lines << chunk

Instance Method Summary collapse

Constructor Details

#initialize {|object| ... } ⇒ JSONLines

Returns a new instance of JSONLines.

Yield Parameters:

  • object (Hash)

    one decoded JSON document

Raises:

  • (ArgumentError)


86
87
88
89
90
91
# File 'lib/docker/api/stream.rb', line 86

def initialize(&block)
  raise ArgumentError, "JSONLines needs a block to yield objects to" unless block

  @block = block
  @buffer = +""
end

Instance Method Details

#<<(chunk) ⇒ self

Parameters:

  • chunk (String)

    any number of bytes, at any boundary

Returns:

  • (self)

Raises:



96
97
98
99
100
# File 'lib/docker/api/stream.rb', line 96

def <<(chunk)
  @buffer << chunk.to_s
  emit_lines
  self
end