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

Returns a new instance of PathPrefix.



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

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

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
# File 'lib/merb-core/rack/middleware/path_prefix.rb', line 15

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

#deferred?(env) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#strip_path_prefix(env) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/merb-core/rack/middleware/path_prefix.rb', line 20

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, '')
      env[path_key] = '/' if env[path_key].empty?
    end
  end
end