Class: CGI::ProgressIO
- Defined in:
- lib/action_controller/cgi_ext/multipart_progress.rb
Overview
:nodoc:
Constant Summary collapse
- MIN_SAVE_INTERVAL =
Number of seconds between session saves
1.0
Instance Attribute Summary collapse
-
#progress ⇒ Object
readonly
Returns the value of attribute progress.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize(orig_io, progress, session) ⇒ ProgressIO
constructor
A new instance of ProgressIO.
- #read(*args) ⇒ Object
- #save_progress ⇒ Object
Constructor Details
#initialize(orig_io, progress, session) ⇒ ProgressIO
Returns a new instance of ProgressIO.
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/action_controller/cgi_ext/multipart_progress.rb', line 57 def initialize(orig_io, progress, session) @session = session @progress = progress @start_time = Time.now @last_save_time = @start_time save_progress super(orig_io) end |
Instance Attribute Details
#progress ⇒ Object (readonly)
Returns the value of attribute progress.
55 56 57 |
# File 'lib/action_controller/cgi_ext/multipart_progress.rb', line 55 def progress @progress end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
55 56 57 |
# File 'lib/action_controller/cgi_ext/multipart_progress.rb', line 55 def session @session end |
Instance Method Details
#finish ⇒ Object
94 95 96 97 |
# File 'lib/action_controller/cgi_ext/multipart_progress.rb', line 94 def finish @session.update ActionController::Base.logger.debug("Finished processing multipart upload in #{@progress.elapsed_seconds.to_s}s") end |
#read(*args) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/action_controller/cgi_ext/multipart_progress.rb', line 68 def read(*args) data = __getobj__.read(*args) if data and data.size > 0 now = Time.now elapsed = now - @start_time progress.update!(data.size, elapsed) if now - @last_save_time > MIN_SAVE_INTERVAL save_progress @last_save_time = now end else ActionController::Base.logger.debug("CGI::ProgressIO#read returns nothing when it should return nil if IO is finished: [#{args.inspect}], a cancelled upload or old FCGI bindings. Resetting the upload progress") progress.reset! save_progress end data end |
#save_progress ⇒ Object
90 91 92 |
# File 'lib/action_controller/cgi_ext/multipart_progress.rb', line 90 def save_progress @session.update end |