class Flatrack::Rewriter
Public Class Methods
new(app, mapping = {}, opts = {})
click to toggle source
# File lib/flatrack/rewriter.rb, line 14 def initialize(app, mapping = {}, opts = {}) @if = opts[:if] || Proc.new { true } @unless = opts[:unless] || Proc.new { false } @app = app @mapping = Hash[mapping.map { |paths| paths.map { |p| File.join '', p } }] end
Public Instance Methods
call(env)
click to toggle source
# File lib/flatrack/rewriter.rb, line 22 def call(env) allow = @if.call(env) && !@unless.call(env) if allow && @mapping.keys.include?(env['PATH_INFO']) env['ORIGINAL_PATH_INFO'] = env['PATH_INFO'] env['PATH_INFO'] = @mapping[env['PATH_INFO']] end @app.call env end