Class: Webmachine::Adapters::LazyRequestBody
- Inherits:
-
Object
- Object
- Webmachine::Adapters::LazyRequestBody
- Defined in:
- lib/webmachine/adapters/lazy_request_body.rb
Overview
Wraps a request body so that it can be passed to Request while still lazily evaluating the body.
Instance Method Summary collapse
-
#each {|chunk| ... } ⇒ Object
Iterates over the body in chunks.
-
#initialize(request) ⇒ LazyRequestBody
constructor
A new instance of LazyRequestBody.
-
#to_s ⇒ Object
Converts the body to a String so you can work with the entire thing.
Constructor Details
#initialize(request) ⇒ LazyRequestBody
Returns a new instance of LazyRequestBody.
7 8 9 |
# File 'lib/webmachine/adapters/lazy_request_body.rb', line 7 def initialize(request) @request = request end |
Instance Method Details
#each {|chunk| ... } ⇒ Object
Iterates over the body in chunks. If the body has previously been read, this method can be called again and get the same sequence of chunks.
22 23 24 25 26 27 28 29 |
# File 'lib/webmachine/adapters/lazy_request_body.rb', line 22 def each if @value @value.each {|chunk| yield chunk } else @value = [] @request.body {|chunk| @value << chunk; yield chunk } end end |
#to_s ⇒ Object
Converts the body to a String so you can work with the entire thing.
13 14 15 |
# File 'lib/webmachine/adapters/lazy_request_body.rb', line 13 def to_s @value ? @value.join : @request.body end |