Class: Merb::Rack::PathPrefix

Inherits:
Middleware show all
Defined in:
lib/merb-core/rack/middleware/path_prefix.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, path_prefix = nil) ⇒ PathPrefix

:api: private



6
7
8
9
# File 'lib/merb-core/rack/middleware/path_prefix.rb', line 6

def initialize(app, path_prefix = nil)
  super(app)
  @path_prefix = /^#{Regexp.escape(path_prefix)}/
end

Instance Method Details

#call(env) ⇒ Object

:api: plugin



18
19
20
21
# File 'lib/merb-core/rack/middleware/path_prefix.rb', line 18

def call(env)
  strip_path_prefix(env) 
  @app.call(env)
end

#deferred?(env) ⇒ Boolean

:api: plugin

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/merb-core/rack/middleware/path_prefix.rb', line 12

def deferred?(env)
  strip_path_prefix(env) 
  @app.deferred?(env)
end

#strip_path_prefix(env) ⇒ Object

:api: private



24
25
26
27
28
29
30
31
# File 'lib/merb-core/rack/middleware/path_prefix.rb', line 24

def strip_path_prefix(env)
  ['PATH_INFO', 'REQUEST_URI'].each do |path_key|
    if env[path_key] =~ @path_prefix
      env[path_key].sub!(@path_prefix, Merb::Const::EMPTY_STRING)
      env[path_key] = Merb::Const::SLASH if env[path_key].empty?
    end
  end
end