Class: Appship::UploadProgress

Inherits:
Object
  • Object
show all
Defined in:
lib/appship/uploader.rb

Constant Summary collapse

BAR_WIDTH =
24

Instance Method Summary collapse

Constructor Details

#initialize(total, output: $stdout) ⇒ UploadProgress

Returns a new instance of UploadProgress.



374
375
376
377
378
379
380
# File 'lib/appship/uploader.rb', line 374

def initialize(total, output: $stdout)
  @total = [total.to_i, 1].max
  @output = output
  @interactive = output.tty?
  @last_percent = -1
  @started = false
end

Instance Method Details

#finishObject



395
396
397
398
399
400
401
402
403
404
# File 'lib/appship/uploader.rb', line 395

def finish
  return unless @started

  render(100, @total)
  if @interactive
    @output.print "\r\e[2K"
    @output.puts "☁️ 上传完成(#{format_size(@total)}"
  end
  @output.flush
end

#startObject



382
383
384
385
# File 'lib/appship/uploader.rb', line 382

def start
  @started = true
  render(0)
end

#update(current, total = @total) ⇒ Object



387
388
389
390
391
392
393
# File 'lib/appship/uploader.rb', line 387

def update(current, total = @total)
  @total = [total.to_i, 1].max
  percent = [[(current.to_i * 100.0 / @total).floor, 0].max, 100].min
  return if percent == @last_percent

  render(percent, current.to_i)
end