class Apipie::StaticDispatcher

Public Class Methods

new(app, path, baseurl) click to toggle source

Dispatches the statis files. Simillar to ActionDispatch::Static, but it supports different baseurl configurations

# File lib/apipie/static_dispatcher.rb, line 39
def initialize(app, path, baseurl)
  @app = app
  @baseurl = baseurl
  @file_handler = Apipie::FileHandler.new(path)
end

Public Instance Methods

call(env) click to toggle source
# File lib/apipie/static_dispatcher.rb, line 45
def call(env)
  case env['REQUEST_METHOD']
  when 'GET', 'HEAD'
    path = env['PATH_INFO'].sub("#{@baseurl}/","/apipie/").chomp('/')
    path.sub!("#{ENV["RAILS_RELATIVE_URL_ROOT"]}",'')

    if match = @file_handler.match?(path)
      env["PATH_INFO"] = match
      return @file_handler.call(env)
    end
  end

  @app.call(env)
end