Class: Trellis::Redirect
Overview
– Redirect – Encapsulates an HTTP redirect (is the object returned by Page#redirect method)
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #apply_to(request, response) ⇒ Object
-
#initialize(target, status = nil) ⇒ Redirect
constructor
A new instance of Redirect.
Constructor Details
#initialize(target, status = nil) ⇒ Redirect
Returns a new instance of Redirect.
488 489 490 491 492 |
# File 'lib/trellis/trellis.rb', line 488 def initialize(target, status=nil) status = 302 unless status raise ArgumentError.new("#{status} is not a valid redirect status") unless status >= 300 && status < 400 @target, @status = target, status end |
Instance Attribute Details
#status ⇒ Object (readonly)
Returns the value of attribute status.
486 487 488 |
# File 'lib/trellis/trellis.rb', line 486 def status @status end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
486 487 488 |
# File 'lib/trellis/trellis.rb', line 486 def target @target end |
Instance Method Details
#apply_to(request, response) ⇒ Object
494 495 496 497 |
# File 'lib/trellis/trellis.rb', line 494 def apply_to(request, response) response.status = status response["Location"] = "#{request.script_name}#{target.starts_with?('/') ? '' : '/'}#{target}" end |