class StaticAssetServer

Attributes

app[R]
file_server[R]
root[R]

Public Class Methods

new(app) click to toggle source
# File lib/static_asset_server.rb, line 4
def initialize(app)
  @app = app
  @root = 'app/assets/'
  @file_server = FileServer.new
end

Public Instance Methods

call(env) click to toggle source
# File lib/static_asset_server.rb, line 10
def call(env)
  req = Rack::Request.new(env)
  path = req.path

  if servable?(path)
    res = file_server.call(env)
  else
    res = app.call(env)
  end
  res.finish
end

Private Instance Methods

servable?(path) click to toggle source
# File lib/static_asset_server.rb, line 23
def servable?(path)
  path.match("#{root}")
end