Class: Gemfury::Command::App::ProgressIO

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/gemfury/command/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_typeObject (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_pathObject (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_filenameObject (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

Returns:

  • (Boolean)


400
401
402
# File 'lib/gemfury/command/app.rb', line 400

def show_bar?
  @bar != nil
end