Class: Async::HTTP::Body::Rewindable
- Defined in:
- lib/async/http/body/rewindable.rb
Overview
A body which buffers all it’s contents.
Instance Method Summary collapse
-
#initialize(body) ⇒ Rewindable
constructor
A new instance of Rewindable.
- #inspect ⇒ Object
- #read ⇒ Object
- #rewind ⇒ Object
Methods inherited from Wrapper
#close, #empty?, #length, #stop
Methods inherited from Readable
#close, #each, #empty?, #join, #length, #stop
Constructor Details
#initialize(body) ⇒ Rewindable
Returns a new instance of Rewindable.
28 29 30 31 32 33 |
# File 'lib/async/http/body/rewindable.rb', line 28 def initialize(body) super(body) @chunks = [] @index = 0 end |
Instance Method Details
#inspect ⇒ Object
53 54 55 |
# File 'lib/async/http/body/rewindable.rb', line 53 def inspect "\#<#{self.class} #{@index}/#{@chunks.count} chunks read>" end |
#read ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/async/http/body/rewindable.rb', line 35 def read if @index < @chunks.count chunk = @chunks[@index] @index += 1 else if chunk = super @chunks << chunk @index += 1 end end return chunk end |
#rewind ⇒ Object
49 50 51 |
# File 'lib/async/http/body/rewindable.rb', line 49 def rewind @index = 0 end |