Class: ReporterHub

Inherits:
Object show all
Defined in:
cmd/update-report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.



744
745
746
747
# File 'cmd/update-report.rb', line 744

def initialize
  @hash = {}
  @reporters = []
end

Instance Attribute Details

#reportersObject (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 the value of attribute reporters.



741
742
743
# File 'cmd/update-report.rb', line 741

def reporters
  @reporters
end

Instance Method Details

#add(reporter, auto_update: false) ⇒ Object



753
754
755
756
757
# File 'cmd/update-report.rb', line 753

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

#dump(auto_update: false) ⇒ Object



763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
# File 'cmd/update-report.rb', line 763

def dump(auto_update: false)
  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, plural: "e")
    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?

  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

Returns:

  • (Boolean)


759
760
761
# File 'cmd/update-report.rb', line 759

def empty?
  @hash.empty?
end

#select_formula_or_cask(key) ⇒ Object



749
750
751
# File 'cmd/update-report.rb', line 749

def select_formula_or_cask(key)
  @hash.fetch(key, [])
end