Class: Gemfury::Command::App::ProgressIO
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Gemfury::Command::App::ProgressIO
- Defined in:
- lib/gemfury/command/app.rb
Instance Attribute Summary collapse
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#local_path ⇒ Object
readonly
Returns the value of attribute local_path.
-
#original_filename ⇒ Object
readonly
Returns the value of attribute original_filename.
Instance Method Summary collapse
-
#initialize(filename_or_io, content_type = 'application/octet-stream', fname = nil) ⇒ ProgressIO
constructor
A new instance of ProgressIO.
- #read(length) ⇒ Object
- #show_bar? ⇒ Boolean
Constructor Details
#initialize(filename_or_io, content_type = 'application/octet-stream', fname = nil) ⇒ ProgressIO
Returns a new instance of ProgressIO.
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/gemfury/command/app.rb', line 367 def initialize(filename_or_io, content_type = 'application/octet-stream', fname = nil) io = filename_or_io local_path = '' if io.respond_to? :read local_path = filename_or_io.respond_to?(:path) ? filename_or_io.path : 'local.path' else io = File.open(filename_or_io) local_path = filename_or_io end fname ||= local_path @content_type = content_type @original_filename = File.basename(fname) @local_path = local_path filesize = if io.respond_to? :size io.size else io.stat.size end if filesize > C50K title = 'Uploading %s ' % File.basename(fname) @bar = ProgressBar.create(title: title, total: filesize) else @bar = nil end super(io) end |
Instance Attribute Details
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
365 366 367 |
# File 'lib/gemfury/command/app.rb', line 365 def content_type @content_type end |
#local_path ⇒ Object (readonly)
Returns the value of attribute local_path.
365 366 367 |
# File 'lib/gemfury/command/app.rb', line 365 def local_path @local_path end |
#original_filename ⇒ Object (readonly)
Returns the value of attribute original_filename.
365 366 367 |
# File 'lib/gemfury/command/app.rb', line 365 def original_filename @original_filename end |
Instance Method Details
#read(length) ⇒ Object
404 405 406 407 408 409 |
# File 'lib/gemfury/command/app.rb', line 404 def read(length) buf = __getobj__.read(length) @bar.progress += buf.bytesize unless @bar.nil? || buf.nil? buf end |
#show_bar? ⇒ Boolean
400 401 402 |
# File 'lib/gemfury/command/app.rb', line 400 def @bar != nil end |