Class: Apipie::StaticDispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/apipie/static_dispatcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, path) ⇒ StaticDispatcher

Dispatches the static files. Similar to ActionDispatch::Static, but it supports different baseurl configurations



57
58
59
60
# File 'lib/apipie/static_dispatcher.rb', line 57

def initialize(app, path)
  @app = app
  @file_handler = Apipie::FileHandler.new(path)
end

Instance Method Details

#call(env) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/apipie/static_dispatcher.rb', line 62

def call(env)
  @baseurl ||= Apipie.configuration.doc_base_url
  case env['REQUEST_METHOD']
  when 'GET', 'HEAD'
    path = env['PATH_INFO'].sub("#{@baseurl}/","/apipie/").chomp('/')

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

  @app.call(env)
end