Class: Mpp::Server::Middleware::RackInputCapture
- Inherits:
-
Object
- Object
- Mpp::Server::Middleware::RackInputCapture
- Extended by:
- T::Sig
- Defined in:
- lib/mpp/server/middleware.rb
Instance Method Summary collapse
- #close ⇒ Object
- #each(&block) ⇒ Object
- #gets(*args) ⇒ Object
-
#initialize(input) ⇒ RackInputCapture
constructor
A new instance of RackInputCapture.
- #materialize ⇒ Object
- #read(*args) ⇒ Object
- #rewind ⇒ Object
Constructor Details
#initialize(input) ⇒ RackInputCapture
Returns a new instance of RackInputCapture.
234 235 236 237 |
# File 'lib/mpp/server/middleware.rb', line 234 def initialize(input) @input = T.let(input, T.untyped) @buffer = T.let(+"".b, String) end |
Instance Method Details
#close ⇒ Object
270 271 272 |
# File 'lib/mpp/server/middleware.rb', line 270 def close @input.close if @input.respond_to?(:close) end |
#each(&block) ⇒ Object
254 255 256 257 258 259 260 261 |
# File 'lib/mpp/server/middleware.rb', line 254 def each(&block) return enum_for(:each) unless block @input.each do |chunk| @buffer << chunk.b if chunk && !chunk.empty? block.call(chunk) end end |
#gets(*args) ⇒ Object
247 248 249 250 251 |
# File 'lib/mpp/server/middleware.rb', line 247 def gets(*args) chunk = @input.gets(*args) @buffer << chunk.b if chunk && !chunk.empty? chunk end |
#materialize ⇒ Object
275 276 277 278 |
# File 'lib/mpp/server/middleware.rb', line 275 def materialize read @buffer.empty? ? nil : @buffer.dup end |
#read(*args) ⇒ Object
240 241 242 243 244 |
# File 'lib/mpp/server/middleware.rb', line 240 def read(*args) chunk = @input.read(*args) @buffer << chunk.b if chunk && !chunk.empty? chunk end |
#rewind ⇒ Object
264 265 266 267 |
# File 'lib/mpp/server/middleware.rb', line 264 def rewind @input.rewind if @input.respond_to?(:rewind) @buffer = +"".b end |