Class: ShopifyCLI::Theme::Extension::UI::HostThemeProgressBar

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify_cli/theme/extension/ui/host_theme_progress_bar.rb

Constant Summary collapse

GIT_CLONE_PROGRESS_SHARE =
0.2
SYNC_PROGRESS_SHARE =
0.8

Instance Method Summary collapse

Constructor Details

#initialize(syncer, dir) ⇒ HostThemeProgressBar

Returns a new instance of HostThemeProgressBar.



10
11
12
13
# File 'lib/shopify_cli/theme/extension/ui/host_theme_progress_bar.rb', line 10

def initialize(syncer, dir)
  @syncer = syncer
  @dir = dir
end

Instance Method Details

#progress(method, **args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/shopify_cli/theme/extension/ui/host_theme_progress_bar.rb', line 15

def progress(method, **args)
  @syncer.lock_io!
  CLI::UI::Progress.progress do |bar|
    Git.public_send(:raw_clone, "https://github.com/Shopify/dawn.git", @dir) do |percent|
      bar.tick(set_percent: percent * GIT_CLONE_PROGRESS_SHARE)
    end

    @syncer.public_send(method, **args) do |left, total|
      next if total == 0
      bar.tick(set_percent: (1 - left.to_f / total) * SYNC_PROGRESS_SHARE + GIT_CLONE_PROGRESS_SHARE)
    end

    bar.tick(set_percent: 1)
  end
  @syncer.unlock_io!
end