Class: MultiDirHandler

Inherits:
Mongrel::DirHandler
  • Object
show all
Defined in:
lib/multi_dirhandler.rb

Overview

Allow files to be servered from multiple directories within a single URL space

This is sometimes very useful when working with multiple application servers, each with their own set of static files.

Usage:

uri "/request_path/", :handler => MultiDirHandler.new(['/file/path1','/file/path2'])

options:

:cwd, override the server root directory, make sure there is a tmp directory in server root

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ MultiDirHandler

check in each folder for the file



19
20
21
22
23
# File 'lib/multi_dirhandler.rb', line 19

def initialize( path, options = {})
  @server_root = (options[:cwd] || SERVER_ROOT)
  @paths = path.flatten
  super(@paths[0])
end

Instance Method Details

#can_serve(path_info) ⇒ Object

check each folder



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/multi_dirhandler.rb', line 26

def can_serve(path_info)
  if check_multifile_request( path_info )
    return handle_multifile_request( path_info )
  else
    @paths.each do|path|
      @path = File.expand_path(path)
      ret = super(path_info)
      return ret unless ret.nil?
    end
  end
  @path = @paths[0]
  return nil
end

#send_file(req_path, request, response, header_only = false) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/multi_dirhandler.rb', line 40

def send_file(req_path, request, response, header_only=false)
  if check_multifile_request( req_path )
    # change the request path
    req_path = cached_filepath( req_path )
  end
  super( req_path, request, response, header_only )
end