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.
106 107 108 109 |
# File 'lib/mpp/server/middleware.rb', line 106 def initialize(input) @input = T.let(input, T.untyped) @buffer = T.let(+"".b, String) end |
Instance Method Details
#close ⇒ Object
142 143 144 |
# File 'lib/mpp/server/middleware.rb', line 142 def close @input.close if @input.respond_to?(:close) end |
#each(&block) ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/mpp/server/middleware.rb', line 126 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
119 120 121 122 123 |
# File 'lib/mpp/server/middleware.rb', line 119 def gets(*args) chunk = @input.gets(*args) @buffer << chunk.b if chunk && !chunk.empty? chunk end |
#materialize ⇒ Object
147 148 149 150 |
# File 'lib/mpp/server/middleware.rb', line 147 def materialize read @buffer.empty? ? nil : @buffer.dup end |
#read(*args) ⇒ Object
112 113 114 115 116 |
# File 'lib/mpp/server/middleware.rb', line 112 def read(*args) chunk = @input.read(*args) @buffer << chunk.b if chunk && !chunk.empty? chunk end |
#rewind ⇒ Object
136 137 138 139 |
# File 'lib/mpp/server/middleware.rb', line 136 def rewind @input.rewind if @input.respond_to?(:rewind) @buffer = +"".b end |