Module: Knot::Dispatch::Router::Context
- Included in:
- Knot::Dispatch::Router
- Defined in:
- lib/knot/dispatch/router/context.rb
Instance Method Summary collapse
- #json(obj) ⇒ Object
- #params ⇒ Object
- #redirect(uri) ⇒ Object
- #render(filename, options = {}) ⇒ Object
-
#respond! ⇒ Object
terminate processing and return to router to handle the given response.
- #status(code) ⇒ Object
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 |
#params ⇒ Object
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, = {}) response.body << Knot::Render.render(filename, _config.template_paths, ) 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 |