class Flatrack::Redirector

Public Class Methods

new(app, mapping = {}, opts = {}) click to toggle source
# File lib/flatrack/redirector.rb, line 15
def initialize(app, mapping = {}, opts = {})
  @if      = opts[:if] || Proc.new { true }
  @unless  = opts[:unless] || Proc.new { false }
  @app     = app
  @mapping =
    Hash[mapping.map { |k, v| [File.join('', k), v] }]
end

Public Instance Methods

call(env) click to toggle source
# File lib/flatrack/redirector.rb, line 23
def call(env)
  allow = @if.call(env) && !@unless.call(env)
  if allow && @mapping.keys.include?(env['PATH_INFO'])
    @mapping[env['PATH_INFO']].response
  else
    @app.call env
  end
end