module Ground::Protocol::Render

Public Instance Methods

forbid(content = nil) click to toggle source
# File lib/ground/protocol/render.rb, line 26
def forbid(content = nil)
  response_as 403, content
end
html(content, status = 200) click to toggle source
# File lib/ground/protocol/render.rb, line 14
def html(content, status = 200)
  response_with(content, status, 'text/html; charset=UTF-8')
end
json(content, status = 200) click to toggle source
# File lib/ground/protocol/render.rb, line 6
def json(content, status = 200)
  response_with(content, status, 'application/json; charset=UTF-8')
end
non_found(content) click to toggle source
# File lib/ground/protocol/render.rb, line 22
def non_found(content)
  response_as 404, content
end
not_accept(content = nil) click to toggle source
# File lib/ground/protocol/render.rb, line 30
def not_accept(content = nil)
  response_as 406, content
end
redirect(target, status = 302) click to toggle source
# File lib/ground/protocol/render.rb, line 38
def redirect(target, status = 302)
  response.status = status
  response['Location'] = target
  response.finish
end
text(content, status = 200) click to toggle source
# File lib/ground/protocol/render.rb, line 18
def text(content, status = 200)
  response_with(content, status, 'text/plain; charset=UTF-8')
end
unauthorized(content = nil) click to toggle source
# File lib/ground/protocol/render.rb, line 34
def unauthorized(content = nil)
  response_as 401, content
end
xml(content, status = 200) click to toggle source
# File lib/ground/protocol/render.rb, line 10
def xml(content, status = 200)
  response_with(content, status, 'application/xml; charset=UTF-8')
end

Private Instance Methods

response_as(status, content=nil) click to toggle source
# File lib/ground/protocol/render.rb, line 46
def response_as(status, content=nil)
  content ||= HTTP_STATUS_CODES[status]
  text content, status
end
response_with(content, status, content_type) click to toggle source
# File lib/ground/protocol/render.rb, line 51
def response_with(content, status, content_type)
  response['Content-Type'] = content_type
  response.status = status
  response.write(content)
  response.finish
end