Class: Rack::Digestif

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/digestif.rb

Overview

Rack middleware which rewrites the REQUEST_PATH to remove the asset digest

Constant Summary collapse

PATTERN =
/-[0-9a-z]{32}(\.[^.]+)\Z/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(app, path = nil) ⇒ Digestif

Returns a new instance of Digestif.



5
6
7
8
# File 'lib/rack/digestif.rb', line 5

def initialize app, path=nil
  @app = app
  @path = path.freeze
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
# File 'lib/rack/digestif.rb', line 9

def call env
  if (not @path) || (@path && env["PATH_INFO"].index(@path) == 0)
    env["PATH_INFO"].gsub! PATTERN, '\1'
  end
  @app.call env
end