Class: ReporterHub

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializevoid



656
657
658
659
# File 'cmd/update-report.rb', line 656

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

Instance Attribute Details

#reportersObject (readonly)

Returns the value of attribute reporters.



653
654
655
# File 'cmd/update-report.rb', line 653

def reporters
  @reporters
end

Instance Method Details

#add(reporter, auto_update: false) ⇒ Object



665
666
667
668
669
# File 'cmd/update-report.rb', line 665

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

#dump(auto_update: false) ⇒ Object



675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
# File 'cmd/update-report.rb', line 675

def dump(auto_update: false)
  report_all = ENV["HOMEBREW_UPDATE_REPORT_ALL_FORMULAE"].present?
  if report_all && !Homebrew::EnvConfig.no_install_from_api?
    odeprecated "HOMEBREW_UPDATE_REPORT_ALL_FORMULAE"
    opoo "This will not report all formulae because Homebrew cannot get this data from the API."
    report_all = false
  end

  dump_new_formula_report
  dump_new_cask_report
  dump_renamed_formula_report if report_all
  dump_renamed_cask_report if report_all
  dump_deleted_formula_report(report_all)
  dump_deleted_cask_report(report_all)

  outdated_formulae = []
  outdated_casks = []

  if !auto_update && report_all
    dump_modified_formula_report
    dump_modified_cask_report
  elsif !auto_update
    outdated_formulae = Formula.installed.select(&:outdated?).map(&:name)
    output_dump_formula_or_cask_report "Outdated Formulae", outdated_formulae

    outdated_casks = Cask::Caskroom.casks.select(&:outdated?).map(&:token)
    output_dump_formula_or_cask_report "Outdated Casks", outdated_casks
  elsif report_all
    if (changed_formulae = select_formula_or_cask(:M).count) && changed_formulae.positive?
      ohai "Modified Formulae",
           "Modified #{Utils.pluralize("formula", changed_formulae, plural: "e", include_count: true)}."
    end

    if (changed_casks = select_formula_or_cask(:MC).count) && changed_casks.positive?
      ohai "Modified Casks", "Modified #{Utils.pluralize("cask", changed_casks, include_count: true)}."
    end
  else
    outdated_formulae = Formula.installed.select(&:outdated?).map(&:name)
    outdated_casks = Cask::Caskroom.casks.select(&:outdated?).map(&:token)
  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)


671
672
673
# File 'cmd/update-report.rb', line 671

def empty?
  @hash.empty?
end

#select_formula_or_cask(key) ⇒ Object



661
662
663
# File 'cmd/update-report.rb', line 661

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