class StaticAssetsServer
Attributes
app[R]
req[R]
res[R]
Public Class Methods
new(app)
click to toggle source
# File lib/asset_server.rb, line 4 def initialize(app) @app = app @res = Rack::Response.new end
Public Instance Methods
call(env)
click to toggle source
# File lib/asset_server.rb, line 9 def call(env) @req = Rack::Request.new(env) if req.path =~ /^\/public\/assets/ serve_asset else app.call(env) end end
Private Instance Methods
serve_asset()
click to toggle source
# File lib/asset_server.rb, line 19 def serve_asset asset = File.read(File.join(PROJECT_ROOT, req.path)) file_type = req.path.match(/\..+$/)[0] res["Content-Type"] = Rack::Mime::MIME_TYPES[file_type] res.write(asset) res.finish end