move admin rack to its own file

This commit is contained in:
Maxwell Salzberg 2011-09-16 13:33:05 -07:00
parent 7ab963f859
commit 17b5e7b066
2 changed files with 20 additions and 19 deletions

View file

@ -30,24 +30,6 @@ end
if AppConfig[:mount_resque_web]
require 'resque/server'
class AdminRack
def initialize(app)
@app = app
end
def call(env)
user = env['warden'].authenticate(:scope => :user)
if user && user.admin?
@app.call(env)
else
[307, {"Location" => '/'}, self]
end
end
def each(&block)
end
end
require File.join(Rails.root, 'lib/admin_rack')
Resque::Server.use AdminRack
end

19
lib/admin_rack.rb Normal file
View file

@ -0,0 +1,19 @@
class AdminRack
def initialize(app)
@app = app
end
def call(env)
user = env['warden'].authenticate(:scope => :user)
if user && user.admin?
@app.call(env)
else
[307, {"Location" => '/'}, self]
end
end
def each(&block)
end
end