Class: Flatrack::Response
- Inherits:
-
Object
- Object
- Flatrack::Response
- Defined in:
- lib/flatrack/response.rb
Constant Summary collapse
- DEFAULT_FILE =
'index'- CONTENT_TYPES =
{ html: 'text/html', rb: 'text/html' }
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #body ⇒ Object
- #headers ⇒ Object
-
#initialize(request) ⇒ Response
constructor
A new instance of Response.
- #render(file: file_for(request.path), status: 200, layout: :layout) ⇒ Object
- #set_content_type ⇒ Object
Constructor Details
#initialize(request) ⇒ Response
Returns a new instance of Response.
11 12 13 |
# File 'lib/flatrack/response.rb', line 11 def initialize(request) @request = request end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
9 10 11 |
# File 'lib/flatrack/response.rb', line 9 def request @request end |
Instance Method Details
#body ⇒ Object
19 20 21 |
# File 'lib/flatrack/response.rb', line 19 def body @body ||= [] end |
#headers ⇒ Object
15 16 17 |
# File 'lib/flatrack/response.rb', line 15 def headers @headers ||= {} end |
#render(file: file_for(request.path), status: 200, layout: :layout) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/flatrack/response.rb', line 23 def render(file: file_for(request.path), status: 200, layout: :layout) page_content = proc { renderer_for_page(file).render(view) } set_content_type body << begin renderer_for_layout(layout).render(view, &page_content) rescue Flatrack::FileNotFound page_content.call end [status, headers, body] end |
#set_content_type ⇒ Object
34 35 36 |
# File 'lib/flatrack/response.rb', line 34 def set_content_type headers['Content-Type'] = CONTENT_TYPES[request.format.to_sym] end |