Class: Webmachine::Adapters::LazyRequestBody

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(request) ⇒ 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.

Yields:

  • (chunk)

Yield Parameters:

  • chunk (String)

    a chunk of the request body


27
28
29
# File 'lib/webmachine/adapters/lazy_request_body.rb', line 27

def each
  @request.body {|chunk| yield chunk }
end

#empty?Boolean

Converts the body to a String and checks if it is empty.


18
19
20
# File 'lib/webmachine/adapters/lazy_request_body.rb', line 18

def empty?
  to_s.empty?
end

#to_sObject

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
  @request.body
end