Class: Rack::TryStatic
- Inherits:
-
Object
- Object
- Rack::TryStatic
- Defined in:
- lib/rack/contrib/try_static.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options) ⇒ TryStatic
constructor
A new instance of TryStatic.
Constructor Details
#initialize(app, options) ⇒ TryStatic
Returns a new instance of TryStatic.
6 7 8 9 10 11 12 |
# File 'lib/rack/contrib/try_static.rb', line 6 def initialize(app, ) @app = app @try = ['', *.delete(:try)] @static = ::Rack::Static.new( lambda { [404, {}, []] }, ) end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/rack/contrib/try_static.rb', line 14 def call(env) orig_path = env['PATH_INFO'] found = nil @try.each do |path| resp = @static.call(env.merge!({'PATH_INFO' => orig_path + path})) break if 404 != resp[0] && found = resp end found or @app.call(env.merge!('PATH_INFO' => orig_path)) end |