class Protocol::HTTP::Body::Rewindable
A body which buffers all it's contents as it is `#read`.
Public Class Methods
new(body)
click to toggle source
Calls superclass method
# File lib/protocol/http/body/rewindable.rb, line 31 def initialize(body) super(body) @chunks = [] @index = 0 end
Public Instance Methods
buffered()
click to toggle source
A rewindable body wraps some other body. Convert it to a buffered body
# File lib/protocol/http/body/rewindable.rb, line 47 def buffered Buffered.new(@chunks) end
empty?()
click to toggle source
Calls superclass method
# File lib/protocol/http/body/rewindable.rb, line 38 def empty? (@index >= @chunks.size) && super end
inspect()
click to toggle source
# File lib/protocol/http/body/rewindable.rb, line 70 def inspect "\#<#{self.class} #{@index}/#{@chunks.size} chunks read>" end
read()
click to toggle source
Calls superclass method
# File lib/protocol/http/body/rewindable.rb, line 51 def read if @index < @chunks.size chunk = @chunks[@index] @index += 1 else if chunk = super @chunks << chunk @index += 1 end end # We dup them on the way out, so that if someone modifies the string, it won't modify the rewindability. return chunk&.dup end
ready?()
click to toggle source
Calls superclass method
# File lib/protocol/http/body/rewindable.rb, line 42 def ready? (@index < @chunks.size) || super end
rewind()
click to toggle source
# File lib/protocol/http/body/rewindable.rb, line 66 def rewind @index = 0 end