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
-
#initialize(target, status = nil) ⇒ Redirect
constructor
A new instance of Redirect.
- #process(request, response) ⇒ Object
Constructor Details
#initialize(target, status = nil) ⇒ Redirect
Returns a new instance of Redirect.
507 508 509 510 511 |
# File 'lib/trellis/trellis.rb', line 507 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.
505 506 507 |
# File 'lib/trellis/trellis.rb', line 505 def status @status end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
505 506 507 |
# File 'lib/trellis/trellis.rb', line 505 def target @target end |
Instance Method Details
#process(request, response) ⇒ Object
513 514 515 516 |
# File 'lib/trellis/trellis.rb', line 513 def process(request, response) response.status = status response["Location"] = "#{request.script_name}#{target.starts_with?('/') ? '' : '/'}#{target}" end |