Class: Rack::App::RequestStream

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rack/app/request_stream.rb

Instance Method Summary collapse

Constructor Details

#initialize(io, parser) ⇒ RequestStream

Returns a new instance of RequestStream.



5
6
7
8
# File 'lib/rack/app/request_stream.rb', line 5

def initialize(io, parser)
  @io = io
  @parser = parser
end

Instance Method Details

#each(&block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/rack/app/request_stream.rb', line 10

def each(&block)
  enum = Enumerator.new do |y|
    @io.rewind
    while chunk = @io.gets
      y << @parser.call(chunk)
    end
  end

  block_given? ? enum.each(&block) : enum
end