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.
-
#empty? ⇒ Boolean
Converts the body to a String and checks if it is empty.
-
#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.
6 7 8 |
# File 'lib/webmachine/adapters/lazy_request_body.rb', line 6 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.
26 27 28 |
# File 'lib/webmachine/adapters/lazy_request_body.rb', line 26 def each @request.body { |chunk| yield chunk } end |
#empty? ⇒ Boolean
Converts the body to a String and checks if it is empty.
17 18 19 |
# File 'lib/webmachine/adapters/lazy_request_body.rb', line 17 def empty? to_s.empty? end |
#to_s ⇒ Object
Converts the body to a String so you can work with the entire thing.
12 13 14 |
# File 'lib/webmachine/adapters/lazy_request_body.rb', line 12 def to_s @request.body end |