Skip to content

Commit

Permalink
pull out redirect responder
Browse files Browse the repository at this point in the history
  • Loading branch information
tcrayford committed Feb 18, 2012
1 parent 3c3f45f commit 4cb70fa
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/raptor/responders.rb
Expand Up @@ -18,14 +18,12 @@ def initialize(app_module, target)
end

def respond(route, subject, injector)
response = Rack::Response.new
if @target.is_a?(String)
path = @target
else
path = resource_path(route, subject)
end
redirect_to(response, path)
response
RedirectResponder.new(path).respond(route, subject, injector)
end

def resource_path(route, subject)
Expand All @@ -38,11 +36,19 @@ def resource_path(route, subject)
end
path
end
end

class RedirectResponder
def initialize(location)
@location = location
end

def redirect_to(response, location)
Raptor.log("Redirecting to #{location}")
def respond(route, subject, injector)
response = Rack::Response.new
Raptor.log("Redirecting to #{@location}")
response.status = 302
response["Location"] = location
response["Location"] = @location
response
end
end

Expand Down

0 comments on commit 4cb70fa

Please sign in to comment.