Class: Rack::FileUpload

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/file_upload.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ FileUpload

Returns a new instance of FileUpload.



8
9
10
11
12
13
14
# File 'lib/rack/file_upload.rb', line 8

def initialize(app, options={})
  @app = app
  @paths = [options[:upload_dir]]
  @explicit = options[:explicit]
  @tmpdir = options[:tmp_dir] || Dir::tmpdir
  @paths = [@paths] if @paths.kind_of?(String)
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
# File 'lib/rack/file_upload.rb', line 16

def call(env)
  kick_in?(env) ? convert_and_pass_on(env) : @app.call(env)
end

#upload_path?(request_path) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
# File 'lib/rack/file_upload.rb', line 20

def upload_path?(request_path)
  return true if @paths.nil?

  @paths.any? do |candidate|
    literal_path_match?(request_path, candidate) || wildcard_path_match?(request_path, candidate)
  end
end