class Response

Attributes

body[R]
headers[R]
status[RW]

Public Class Methods

new(body = [], status = 200, headers = {'Content-Type' => 'application/json; charset=utf-8'}) click to toggle source
# File lib/bigsword/response.rb, line 10
def initialize(body = [], status = 200, headers = {'Content-Type' => 'application/json; charset=utf-8'})
  @body, @headers, @status = [], headers, status
  # @length = 0

  if body.respond_to? :to_str
    write body.to_str
  elsif body.respond_to? :each
    body.each { |i| write i.to_s }
  else
    raise TypeError, 'body must #respond_to? #to_str or #each'
  end
end

Public Instance Methods

body=(value) click to toggle source
# File lib/bigsword/response.rb, line 35
def body=(value)
  value.class == Array or value = [value]
  @body = value
end
finish() click to toggle source
# File lib/bigsword/response.rb, line 23
def finish
  result = body.first.to_json

  headers['Content-Length'] = result.bytesize.to_s
  [status, headers, [result]]
end
redirect(target, status = 302) click to toggle source
# File lib/bigsword/response.rb, line 30
def redirect(target, status = 302)
  self.status = status
  headers['Location'] = target
end