class Static

Attributes

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

Public Class Methods

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

Public Instance Methods

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

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

  res
end

Private Instance Methods

can_serve?(path) click to toggle source
# File lib/static.rb, line 25
def can_serve?(path)
  path.index("/#{root}")
end