Class: StaticAssets
- Inherits:
-
Object
- Object
- StaticAssets
- Defined in:
- lib/static_assets.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ StaticAssets
constructor
A new instance of StaticAssets.
Constructor Details
permalink #initialize(app) ⇒ StaticAssets
Returns a new instance of StaticAssets.
2 3 4 |
# File 'lib/static_assets.rb', line 2 def initialize(app) @app = app end |
Instance Method Details
permalink #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 |