Class: Cuprum::Rails::Responses::Html::RedirectResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/cuprum/rails/responses/html/redirect_response.rb

Overview

Encapsulates an HTML response that redirects to a given path.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, flash: {}, status: 302) ⇒ RedirectResponse

Returns a new instance of RedirectResponse.

Parameters:

  • flash (Hash) (defaults to: {})

    the flash messages to set.

  • path (String)

    the path or url to redirect to.

  • status (Integer) (defaults to: 302)

    the HTTP status of the response.



11
12
13
14
15
# File 'lib/cuprum/rails/responses/html/redirect_response.rb', line 11

def initialize(path, flash: {}, status: 302)
  @flash  = flash
  @path   = path
  @status = status
end

Instance Attribute Details

#flashHash (readonly)

Returns the flash messages to set.

Returns:

  • (Hash)

    the flash messages to set.



18
19
20
# File 'lib/cuprum/rails/responses/html/redirect_response.rb', line 18

def flash
  @flash
end

#pathString (readonly)

Returns the path or url to redirect to.

Returns:

  • (String)

    the path or url to redirect to.



21
22
23
# File 'lib/cuprum/rails/responses/html/redirect_response.rb', line 21

def path
  @path
end

#statusInteger (readonly)

Returns the HTTP status of the response.

Returns:

  • (Integer)

    the HTTP status of the response.



24
25
26
# File 'lib/cuprum/rails/responses/html/redirect_response.rb', line 24

def status
  @status
end

Instance Method Details

#call(renderer) ⇒ Object

Calls the renderer’s #redirect_to method with the path and status.

Parameters:

  • renderer (#redirect_to)

    The tontext for executing the response, such as a Rails controller.



30
31
32
33
34
# File 'lib/cuprum/rails/responses/html/redirect_response.rb', line 30

def call(renderer)
  assign_flash(renderer)

  renderer.redirect_to(path, status: status)
end