Skip to content

Commit

Permalink
Improve the documentation on these new wrapper classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
seancribbs committed Feb 9, 2012
1 parent 8bf7d1c commit e6e4a17
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/webmachine/adapters/mongrel.rb
Expand Up @@ -31,7 +31,7 @@ def run
class Handler < ::Mongrel::HttpHandler
def initialize(dispatcher)
@dispatcher = dispatcher
super
super()
end

# Processes an individual request from Mongrel through Webmachine.
Expand Down Expand Up @@ -81,18 +81,26 @@ def process(wreq, wres)
end
end # class Handler

# Wraps a Mongrel request body so that it can behave like a
# String.
# @api private
class RequestBody
# @return the request from Mongrel
attr_reader :request

# @param request the request from Mongrel
def initialize(request)
@request = request
end

# @return [String] the request body as a string
def to_s
request.body.rewind
request.body.read
end

# @yield [chunk]
# @yieldparam [String] chunk a chunk of the request body
def each(&block)
request.body.each(&block)
end
Expand Down
5 changes: 5 additions & 0 deletions lib/webmachine/adapters/rack.rb
Expand Up @@ -64,13 +64,18 @@ def call(env)
[response.code.to_i, response.headers, body || []]
end

# Wraps the Rack input so it can be treated like a String or
# Enumerable.
# @api private
class RequestBody
# @param [Rack::Request] request the Rack request
def initialize(request)
@request = request
end

# Converts the body to a String so you can work with the entire
# thing.
# @return [String] the request body as a string
def to_s
if @value
@value.join
Expand Down

0 comments on commit e6e4a17

Please sign in to comment.