Module: Knot::Dispatch::Router::Context

Included in:
Knot::Dispatch::Router
Defined in:
lib/knot/dispatch/router/context.rb

Instance Method Summary collapse

Instance Method Details

#json(obj) ⇒ Object



22
23
24
25
26
# File 'lib/knot/dispatch/router/context.rb', line 22

def json(obj)
  response.body << obj.to_json
  response.headers["Content-Type"] = "application/json"
  respond!
end

#paramsObject



8
9
10
# File 'lib/knot/dispatch/router/context.rb', line 8

def params
  request.params
end

#redirect(uri) ⇒ Object



16
17
18
19
20
# File 'lib/knot/dispatch/router/context.rb', line 16

def redirect(uri)
  status(302)
  response.headers['Location'] = uri
  respond!
end

#render(filename, options = {}) ⇒ Object



28
29
30
31
# File 'lib/knot/dispatch/router/context.rb', line 28

def render(filename, options = {})
  response.body << Knot::Render.render(filename, _config.template_paths, options)
  respond!
end

#respond!Object

terminate processing and return to router to handle the given response



34
35
36
# File 'lib/knot/dispatch/router/context.rb', line 34

def respond!
  throw(:halt, response)
end

#status(code) ⇒ Object



12
13
14
# File 'lib/knot/dispatch/router/context.rb', line 12

def status(code)
  response.status = code
end