Class: Upload

Inherits:
Object
  • Object
show all
Includes:
Mongrel::HttpHandlerPlugin
Defined in:
lib/haikulearning_mongrel_upload_progress/init.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Upload

Returns a new instance of Upload.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/haikulearning_mongrel_upload_progress/init.rb', line 8

def initialize(options = {})
  @path_info      = Array(options[:path_info])
  @frequency      = options[:frequency] || 3
  @request_notify = true
  if options[:drb]
    require 'drb'
    DRb.start_service
    Mongrel.const_set :Uploads, DRbObject.new(nil, options[:drb])
  else
    Mongrel.const_set :Uploads, Mongrel::UploadProgress.new
  end
  Mongrel::Uploads.debug = true if options[:debug]
end

Instance Method Details

#process(request, response) ⇒ Object



30
31
32
# File 'lib/haikulearning_mongrel_upload_progress/init.rb', line 30

def process(request, response)
  upload_notify(:finish, request.params)
end

#request_begins(params) ⇒ Object



22
23
24
# File 'lib/haikulearning_mongrel_upload_progress/init.rb', line 22

def request_begins(params)
  upload_notify(:add, params, params[Mongrel::Const::CONTENT_LENGTH].to_i)
end

#request_progress(params, clen, total) ⇒ Object



26
27
28
# File 'lib/haikulearning_mongrel_upload_progress/init.rb', line 26

def request_progress(params, clen, total)
  upload_notify(:mark, params, clen)
end