Class: Shorty::RootRedirect

Inherits:
Object
  • Object
show all
Defined in:
lib/shorty/root_redirect.rb

Instance Method Summary collapse

Constructor Details

#initialize(url = '/new', status = 302) ⇒ RootRedirect

Returns a new instance of RootRedirect.



3
4
5
# File 'lib/shorty/root_redirect.rb', line 3

def initialize(url='/new', status=302)
  @url, @status = url, status
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/shorty/root_redirect.rb', line 7

def call(env)
  if env['REQUEST_PATH'] == '/' and env['REQUEST_METHOD'] == 'GET'
    [ @status, { 'Content-Type' => 'text/html', 'Location' => @url }, @url ]
  else
    [ 404, { 'Content-Type' => 'text/html' }, '']
  end
end