Class: Protocol::HTTP::Body::Rewindable
- Inherits:
-
Wrapper
show all
- Defined in:
- lib/protocol/http/body/rewindable.rb
Overview
A body which buffers all it’s contents as it is ‘#read`.
Instance Attribute Summary
Attributes inherited from Wrapper
#body
Instance Method Summary
collapse
Methods inherited from Wrapper
#call, #close, #finish, #length, wrap
Methods inherited from Readable
#call, #close, #each, #finish, #join, #length
Constructor Details
Returns a new instance of Rewindable.
14
15
16
17
18
19
|
# File 'lib/protocol/http/body/rewindable.rb', line 14
def initialize(body)
super(body)
@chunks = []
@index = 0
end
|
Instance Method Details
#buffered ⇒ Object
A rewindable body wraps some other body. Convert it to a buffered body
30
31
32
|
# File 'lib/protocol/http/body/rewindable.rb', line 30
def buffered
Buffered.new(@chunks)
end
|
#empty? ⇒ Boolean
21
22
23
|
# File 'lib/protocol/http/body/rewindable.rb', line 21
def empty?
(@index >= @chunks.size) && super
end
|
#inspect ⇒ Object
57
58
59
|
# File 'lib/protocol/http/body/rewindable.rb', line 57
def inspect
"\#<#{self.class} #{@index}/#{@chunks.size} chunks read>"
end
|
#read ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/protocol/http/body/rewindable.rb', line 38
def read
if @index < @chunks.size
chunk = @chunks[@index]
@index += 1
else
if chunk = super
@chunks << -chunk
@index += 1
end
end
return chunk
end
|
#ready? ⇒ Boolean
25
26
27
|
# File 'lib/protocol/http/body/rewindable.rb', line 25
def ready?
(@index < @chunks.size) || super
end
|
#rewind ⇒ Object
53
54
55
|
# File 'lib/protocol/http/body/rewindable.rb', line 53
def rewind
@index = 0
end
|
#stream? ⇒ Boolean
34
35
36
|
# File 'lib/protocol/http/body/rewindable.rb', line 34
def stream?
false
end
|