Module: DataShifter::Internal::ProgressBar

Defined in:
lib/data_shifter/internal/progress_bar.rb

Overview

Progress bar creation utility. All methods are stateless module functions.

Class Method Summary collapse

Class Method Details

.create(total:, dry_run:, enabled:) ⇒ ProgressBar::Base?

Create a progress bar for iteration. Returns nil if progress is disabled or total is too small.

Parameters:

  • total (Integer)

    total number of items

  • dry_run (Boolean)

    whether running in dry run mode

  • enabled (Boolean)

    whether progress bar is enabled

Returns:

  • (ProgressBar::Base, nil)

    the progress bar or nil



17
18
19
20
21
22
23
24
25
26
# File 'lib/data_shifter/internal/progress_bar.rb', line 17

def create(total:, dry_run:, enabled:)
  return unless enabled && total >= 5

  require "ruby-progressbar"
  ::ProgressBar.create(
    total:,
    format: "%t: |%B| %c/%C (%P%%) %e",
    title: dry_run ? "Dry run" : "Processing",
  )
end