Class: ReactOnRailsPro::RendererHttpClient::MultipartBody
- Inherits:
-
Protocol::HTTP::Body::Readable
- Object
- Protocol::HTTP::Body::Readable
- ReactOnRailsPro::RendererHttpClient::MultipartBody
- Defined in:
- lib/react_on_rails_pro/renderer_http_client.rb,
sig/react_on_rails_pro/renderer_http_client.rbs
Instance Method Summary collapse
- #<<(chunk) ⇒ Object
- #close(error = nil) ⇒ Object
-
#initialize ⇒ MultipartBody
constructor
A new instance of MultipartBody.
- #read ⇒ String?
Constructor Details
#initialize ⇒ MultipartBody
Returns a new instance of MultipartBody.
141 142 143 144 145 146 |
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 141 def initialize super() @chunks = [] @index = 0 @closed = false end |
Instance Method Details
#<<(chunk) ⇒ Object
148 149 150 |
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 148 def <<(chunk) @chunks << (chunk.respond_to?(:read) ? chunk : chunk.to_s.b) end |
#close(error = nil) ⇒ Object
171 172 173 174 175 |
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 171 def close(error = nil) @closed = true @chunks[@index..]&.each { |chunk| chunk.close if chunk.respond_to?(:close) } super end |
#read ⇒ String?
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/react_on_rails_pro/renderer_http_client.rb', line 152 def read return if @closed while @index < @chunks.length chunk = @chunks[@index] if chunk.respond_to?(:read) data = chunk.read return data if data chunk.close if chunk.respond_to?(:close) @index += 1 next end @index += 1 return chunk end end |