Class: Rack::ClassyAssets

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ClassyAssets

Returns a new instance of ClassyAssets.



10
11
12
13
# File 'lib/rack/classy_assets.rb', line 10

def initialize(app)
  @app = app
  @file_server = ::Rack::File.new(::ClassyAssets.config.asset_public_path, { 'Cache-Control' => 'public, max-age=31536000' })
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rack/classy_assets.rb', line 15

def call(env)
  if %w(GET HEAD).include?(env['REQUEST_METHOD']) and env['PATH_INFO'].start_with?("/#{::ClassyAssets.config.asset_prefix}")
    request = Rack::Request.new(env)
    encoding = Rack::Utils.select_best_encoding(%w(gzip identity), request.accept_encoding)
    if encoding == 'gzip'
      return serve_gzipped_asset(env)
    else
      return serve_asset(env)
    end
  end
  
  status, headers, body = @app.call(env)
  body.close if body.respond_to?(:close)
  [status, headers, body]
end