class Rack::AppMapper

Constants

NOT_FOUND

Attributes

apps[R]

Public Class Methods

new(apps, app_map = {}, catch = [404, 405]) click to toggle source
# File lib/marfa/rack/app_mapper.rb, line 7
def initialize(apps, app_map = {}, catch = [404, 405])
  @apps = []
  @has_app = {}
  @app_map = app_map

  apps.each { |app| add app }

  @catch = {}
  [*catch].each { |status| @catch[status] = true }
end

Public Instance Methods

<<(app)
Alias for: add
add(app) click to toggle source
# File lib/marfa/rack/app_mapper.rb, line 33
def add(app)
  @has_app[app] = true
  @apps << app
end
Also aliased as: <<
call(env) click to toggle source
# File lib/marfa/rack/app_mapper.rb, line 18
def call(env)
  res = NOT_FOUND

  @app_map.keys.each do |key|
    uri = env['PATH_INFO']
    next unless uri == key.to_s || uri.include?(key.to_s)

    app = @app_map[key]
    res = app.call(env)
    break
  end

  res
end
include?(app) click to toggle source
# File lib/marfa/rack/app_mapper.rb, line 38
def include?(app)
  @has_app.include? app
end