Class: Protocol::Rack::Body::Streaming

Inherits:
HTTP::Body::Readable
  • Object
show all
Defined in:
lib/protocol/rack/body/streaming.rb

Overview

Wraps a streaming response body into a compatible Protocol::HTTP body.

Defined Under Namespace

Classes: Output

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block, input = nil) ⇒ Streaming

Returns a new instance of Streaming.



14
15
16
17
18
# File 'lib/protocol/rack/body/streaming.rb', line 14

def initialize(block, input = nil)
	@block = block
	@input = input
	@output = nil
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



20
21
22
# File 'lib/protocol/rack/body/streaming.rb', line 20

def block
  @block
end

Instance Method Details

#call(stream) ⇒ Object



54
55
56
57
# File 'lib/protocol/rack/body/streaming.rb', line 54

def call(stream)
	raise "Streaming body has already been read!" if @output
	@block.call(stream)
end

#readObject

Invokes the block in a fiber which yields chunks when they are available.



45
46
47
48
# File 'lib/protocol/rack/body/streaming.rb', line 45

def read
	@output ||= Output.new(@input, @block)
	return @output.read
end

#stream?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/protocol/rack/body/streaming.rb', line 50

def stream?
	true
end