Skip to content

Commit

Permalink
document Response
Browse files Browse the repository at this point in the history
  • Loading branch information
rkh committed May 25, 2011
1 parent 3fbd965 commit fb5b264
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/sinatra/base.rb
Expand Up @@ -73,16 +73,28 @@ def accept_entry(entry)
# more info:
# http://rack.rubyforge.org/doc/classes/Rack/Response.html
# http://rack.rubyforge.org/doc/classes/Rack/Response/Helpers.html
#
# @attr [#each] body
class Response < Rack::Response
def body=(value)
value = value.body while value.respond_to? :body and value.body != value
@body = value.respond_to?(:to_str) ? [value.to_str] : value
end

# @overload each
# Delegates #each to #body.
# @yieldparam [String] chunk
#
# @overload each
# @example
# response.each.map(&:upcase)
# @return [Enumerator, Enumerable::Enumerator]
def each
block_given? ? super : enum_for(:each)
end

# Generates Rack return value from response.
# @return [Array<Integer, Hash, #each>]
def finish
if body.respond_to? :to_ary and not [204, 304].include?(status.to_i)
headers["Content-Length"] = body.inject(0) { |l, p| l + Rack::Utils.bytesize(p) }.to_s
Expand Down

0 comments on commit fb5b264

Please sign in to comment.