sharieswebsite/rack/trystatic.rb
Yann Esposito (Yogsototh) a443134757 Initialization
2011-04-04 16:09:11 +02:00

25 lines
571 B
Ruby

require 'rubygems'
require 'rack'
module ::Rack
class TryStatic < Static
def initialize(app, options)
super
@try = ([''] + Array(options.delete(:try)) + [''])
end
def call(env)
@next = 0
while @next < @try.size && 404 == (resp = super(try_next(env)))[0]
@next += 1
end
404 == resp[0] ? @app.call : resp
end
private
def try_next(env)
env.merge('PATH_INFO' => env['PATH_INFO'] + @try[@next])
end
end
end