Module: Lich::Util::Update::StatusReporter

Defined in:
documented/common/update/status_reporter.rb

Class Method Summary collapse

Class Method Details

.render_sync_summary(repo_name, script_count, downloaded_scripts, downloaded_other, subdir_names, failed_scripts = [], failed_other = {}) ⇒ void

This method returns an undefined value.

Renders a summary of the synchronization process.

Examples:

Render a sync summary

render_sync_summary("my_repo", 5, ["script1.rb", "script2.rb"], {}, ["subdir1", "subdir2"], ["script3.rb"], {"subdir1" => ["file1.txt"]})

Parameters:

  • repo_name (String)

    the name of the repository

  • script_count (Integer)

    the number of scripts checked

  • downloaded_scripts (Array<String>)

    the list of downloaded scripts

  • downloaded_other (Hash)

    a hash of other downloaded files categorized by subdirectory

  • subdir_names (Array<String>)

    the names of subdirectories

  • failed_scripts (Array<String>) (defaults to: [])

    the list of failed scripts (default: [])

  • failed_other (Hash) (defaults to: {})

    a hash of failed files categorized by subdirectory (default: {})



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'documented/common/update/status_reporter.rb', line 44

def self.render_sync_summary(repo_name, script_count, downloaded_scripts, downloaded_other, subdir_names, failed_scripts = [], failed_other = {})
  total_downloaded = downloaded_scripts.length + downloaded_other.values.flatten.length
  total_failed = failed_scripts.length + failed_other.values.flatten.length

  if total_downloaded == 0 && total_failed == 0
    table = Terminal::Table.new(
      title: "#{repo_name} Sync",
      rows: [
        ['Scripts', "#{script_count} checked, all up to date"],
        *subdir_names.map { |s| [s.capitalize, 'up to date'] }
      ]
    )
    respond_mono(table.to_s)
    return
  end

  table_rows = []
  table_rows << ['Category', 'File', 'Status']
  table_rows << :separator

  downloaded_scripts.each { |f| table_rows << ['script', f, 'downloaded'] }
  failed_scripts.each { |f| table_rows << ['script', f, 'FAILED (will retry next login)'] }

  downloaded_other.each do |subdir, files|
    files.each { |f| table_rows << [subdir, f, 'downloaded'] }
  end

  failed_other.each do |subdir, files|
    files.each { |f| table_rows << [subdir, f, 'FAILED (will retry next login)'] }
  end

  subdir_names.each do |s|
    next if downloaded_other.key?(s) || failed_other.key?(s)

    table_rows << [s, '--', 'up to date']
  end

  if downloaded_scripts.empty? && failed_scripts.empty?
    table_rows << ['scripts', '--', "#{script_count} checked, all up to date"]
  end

  table_rows << :separator
  summary = "Total: #{total_downloaded} updated"
  summary += ", #{total_failed} failed" if total_failed > 0
  table_rows << [{ value: summary, colspan: 3 }]

  table = Terminal::Table.new(title: "#{repo_name} Sync", rows: table_rows)
  respond_mono(table.to_s)
end

.respond_mono(text) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Renders the given text in a monospace format.

Parameters:

  • text (String)

    the text to render in monospace

Returns:

  • (String)

    the rendered monospace text



22
23
24
25
26
27
28
29
30
# File 'documented/common/update/status_reporter.rb', line 22

def self.respond_mono(text)
  if defined?(Lich::Messaging) && Lich::Messaging.respond_to?(:mono)
    Lich::Messaging.mono(text)
  else
    # respond is a top-level method (private on Object). Bare `respond`
    # can't be called from a module class method without send.
    send(:respond, text)
  end
end