Class: Cuprum::Rails::Responses::Html::RenderResponse
- Inherits:
-
Object
- Object
- Cuprum::Rails::Responses::Html::RenderResponse
- Defined in:
- lib/cuprum/rails/responses/html/render_response.rb
Overview
Encapsulates an HTML response that renders a given template.
Instance Attribute Summary collapse
-
#assigns ⇒ Hash
readonly
Variables to assign when rendering the template.
-
#flash ⇒ Hash
readonly
The flash messages to set.
-
#layout ⇒ String
readonly
The layout to render.
-
#status ⇒ Integer
readonly
The HTTP status of the response.
-
#template ⇒ String, Symbol
readonly
The template to render.
Instance Method Summary collapse
-
#call(renderer) ⇒ Object
Calls the renderer’s #render method with the template and parameters.
-
#initialize(template, assigns: {}, flash: {}, layout: nil, status: 200) ⇒ RenderResponse
constructor
A new instance of RenderResponse.
Constructor Details
#initialize(template, assigns: {}, flash: {}, layout: nil, status: 200) ⇒ RenderResponse
Returns a new instance of RenderResponse.
13 14 15 16 17 18 19 |
# File 'lib/cuprum/rails/responses/html/render_response.rb', line 13 def initialize(template, assigns: {}, flash: {}, layout: nil, status: 200) @assigns = assigns @flash = flash @layout = layout @status = status @template = template end |
Instance Attribute Details
#assigns ⇒ Hash (readonly)
Returns variables to assign when rendering the template.
22 23 24 |
# File 'lib/cuprum/rails/responses/html/render_response.rb', line 22 def assigns @assigns end |
#flash ⇒ Hash (readonly)
Returns the flash messages to set.
25 26 27 |
# File 'lib/cuprum/rails/responses/html/render_response.rb', line 25 def flash @flash end |
#layout ⇒ String (readonly)
Returns the layout to render.
28 29 30 |
# File 'lib/cuprum/rails/responses/html/render_response.rb', line 28 def layout @layout end |
#status ⇒ Integer (readonly)
Returns the HTTP status of the response.
31 32 33 |
# File 'lib/cuprum/rails/responses/html/render_response.rb', line 31 def status @status end |
#template ⇒ String, Symbol (readonly)
Returns the template to render.
34 35 36 |
# File 'lib/cuprum/rails/responses/html/render_response.rb', line 34 def template @template end |
Instance Method Details
#call(renderer) ⇒ Object
Calls the renderer’s #render method with the template and parameters.
40 41 42 43 44 45 46 47 48 |
# File 'lib/cuprum/rails/responses/html/render_response.rb', line 40 def call(renderer) assign_flash(renderer) assign_variables(renderer) = { status: status } [:layout] = layout if layout renderer.render(template, **) end |