Class: Trellis::Redirect

Inherits:
Object show all
Defined in:
lib/trellis/trellis.rb

Overview

– Redirect – Encapsulates an HTTP redirect (is the object returned by Page#redirect method)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, status = nil) ⇒ Redirect

Returns a new instance of Redirect.

Raises:

  • (ArgumentError)


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

#statusObject (readonly)

Returns the value of attribute status.



505
506
507
# File 'lib/trellis/trellis.rb', line 505

def status
  @status
end

#targetObject (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