Class: Rad::StaticFiles

Inherits:
Object show all
Defined in:
lib/rad/http/middleware/static_files.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, dir, filter = nil) ⇒ StaticFiles

Returns a new instance of StaticFiles.



4
5
6
7
8
9
# File 'lib/rad/http/middleware/static_files.rb', line 4

def initialize(app, dir, filter = nil)
  @app = app
  @dir = File.expand_path(dir)
  @file_server = Rack::File.new(@dir)
  @filter = filter
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/rad/http/middleware/static_files.rb', line 11

def call(env)
  path = env["PATH_INFO"]

  if (!@filter or (@filter and @filter =~ path)) and File.exist?("#{@dir}#{path}")
    @file_server.call(env)
  else
    @app.call(env)
  end
end