Class: StaticAssets

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ StaticAssets

Returns a new instance of StaticAssets.

[View source]

2
3
4
# File 'lib/static_assets.rb', line 2

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object

[View source]

6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/static_assets.rb', line 6

def call(env)
  file_path = "." + env['PATH_INFO']
  res = Rack::Response.new
  extension = /\.(\w*$)/.match(file_path)[1]
  begin
    res['Content-Type'] = set_content_type(extension)
    content = File.read(file_path)
    res.write(content)
  rescue
    res.status = 404
  end

  res.finish
end