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.
102 103 104 105 |
# File 'lib/mpp/server/middleware.rb', line 102 def initialize(input) @input = T.let(input, T.untyped) @buffer = T.let(+"".b, String) end |
Instance Method Details
#close ⇒ Object
138 139 140 |
# File 'lib/mpp/server/middleware.rb', line 138 def close @input.close if @input.respond_to?(:close) end |
#each(&block) ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'lib/mpp/server/middleware.rb', line 122 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
115 116 117 118 119 |
# File 'lib/mpp/server/middleware.rb', line 115 def gets(*args) chunk = @input.gets(*args) @buffer << chunk.b if chunk && !chunk.empty? chunk end |
#materialize ⇒ Object
143 144 145 146 |
# File 'lib/mpp/server/middleware.rb', line 143 def materialize read @buffer.empty? ? nil : @buffer.dup end |
#read(*args) ⇒ Object
108 109 110 111 112 |
# File 'lib/mpp/server/middleware.rb', line 108 def read(*args) chunk = @input.read(*args) @buffer << chunk.b if chunk && !chunk.empty? chunk end |
#rewind ⇒ Object
132 133 134 135 |
# File 'lib/mpp/server/middleware.rb', line 132 def rewind @input.rewind if @input.respond_to?(:rewind) @buffer = +"".b end |