Class: ReporterHub

Inherits:
Object show all
Includes:
Utils::Output::Mixin
Defined in:
cmd/update_report/reporter_hub.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Constructor Details

#initializevoid

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



13
14
15
16
# File 'cmd/update_report/reporter_hub.rb', line 13

def initialize
  @hash = T.let({}, T::Hash[Symbol, T.any(T::Array[String], T::Array[[String, String]])])
  @reporters = T.let([], T::Array[Reporter])
end

Instance Attribute Details

#reportersArray<Reporter> (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



10
11
12
# File 'cmd/update_report/reporter_hub.rb', line 10

def reporters
  @reporters
end

Instance Method Details

#add(reporter, auto_update: false) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • reporter (Reporter)
  • auto_update (Boolean) (defaults to: false)


31
32
33
34
35
# File 'cmd/update_report/reporter_hub.rb', line 31

def add(reporter, auto_update: false)
  @reporters << reporter
  report = reporter.report(auto_update:).reject { |_k, v| v.empty? }
  @hash.update(report) { |_key, oldval, newval| oldval + newval }
end

#dump(auto_update: false) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • auto_update (Boolean) (defaults to: false)


43
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
93
94
95
96
97
98
99
100
# File 'cmd/update_report/reporter_hub.rb', line 43

def dump(auto_update: false)
  return if auto_update && Homebrew::EnvConfig.auto_update_quiet?

  unless Homebrew::EnvConfig.no_update_report_new?
    dump_new_formula_report
    dump_new_cask_report
  end

  dump_deleted_formula_report
  dump_deleted_cask_report

  outdated_formulae = Formula.installed.select(&:outdated?).map(&:name)
  outdated_casks = Cask::Caskroom.casks.select(&:outdated?).map(&:token)
  unless auto_update
    output_dump_formula_or_cask_report "Outdated Formulae", outdated_formulae
    output_dump_formula_or_cask_report "Outdated Casks", outdated_casks
  end
  return if outdated_formulae.blank? && outdated_casks.blank?

  outdated_formulae = outdated_formulae.count
  outdated_casks = outdated_casks.count

  update_pronoun = if (outdated_formulae + outdated_casks) == 1
    "it"
  else
    "them"
  end

  msg = ""

  if outdated_formulae.positive?
    noun = Utils.pluralize("formula", outdated_formulae)
    msg += "#{Tty.bold}#{outdated_formulae}#{Tty.reset} outdated #{noun}"
  end

  if outdated_casks.positive?
    msg += " and " if msg.present?
    msg += "#{Tty.bold}#{outdated_casks}#{Tty.reset} outdated #{Utils.pluralize("cask", outdated_casks)}"
  end

  return if msg.blank?

  # When auto-updating before a zero-argument `brew upgrade` or `brew outdated`,
  # that command lists the outdated packages itself so don't duplicate it here.
  # Two-way sync: `auto-update` in `Library/Homebrew/brew.sh`.
  return if auto_update && ENV["HOMEBREW_AUTO_UPDATE_SKIP_OUTDATED"].present?

  puts
  puts "You have #{msg} installed."
  # If we're auto-updating, don't need to suggest commands that we're perhaps
  # already running.
  return if auto_update

  puts <<~EOS
    You can upgrade #{update_pronoun} with #{Tty.bold}brew upgrade#{Tty.reset}
    or list #{update_pronoun} with #{Tty.bold}brew outdated#{Tty.reset}.
  EOS
end

#empty?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


38
39
40
# File 'cmd/update_report/reporter_hub.rb', line 38

def empty?
  @hash.empty?
end

#renamed_formulaeArray<Array<(String, String)>>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



26
27
28
# File 'cmd/update_report/reporter_hub.rb', line 26

def renamed_formulae
  T.cast(@hash.fetch(:R, []), T::Array[[String, String]])
end

#select_formula_or_cask(key) ⇒ Array<String>, Array<Array<(String, String)>>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



19
20
21
22
23
# File 'cmd/update_report/reporter_hub.rb', line 19

def select_formula_or_cask(key)
  raise "Unsupported key #{key}" unless [:A, :AC, :D, :DC, :M, :MC, :R, :RC, :T].include?(key)

  @hash.fetch(key, [])
end