Class: ReporterHub

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
cmd/update-report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializevoid



561
562
563
564
# File 'cmd/update-report.rb', line 561

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

Instance Attribute Details

#reportersObject (readonly)

Returns the value of attribute reporters.



558
559
560
# File 'cmd/update-report.rb', line 558

def reporters
  @reporters
end

Instance Method Details

#add(reporter, auto_update: false) ⇒ Object



570
571
572
573
574
# File 'cmd/update-report.rb', line 570

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(updated_formula_report: true) ⇒ Object



578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
# File 'cmd/update-report.rb', line 578

def dump(updated_formula_report: true)
  report_all = Homebrew::EnvConfig.update_report_all_formulae?

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

  outdated_formulae = nil
  outdated_casks = nil

  if updated_formula_report && report_all
    dump_modified_formula_report
    dump_modified_cask_report
  elsif updated_formula_report
    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 #{changed_formulae} #{"formula".pluralize(changed_formulae)}."
    end

    if (changed_casks = select_formula_or_cask(:MC).count) && changed_casks.positive?
      ohai "Modified Casks", "Modified #{changed_casks} #{"cask".pluralize(changed_casks)}."
    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?
    msg += "#{Tty.bold}#{outdated_formulae}#{Tty.reset} outdated #{"formula".pluralize(outdated_formulae)}"
  end

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

  return if msg.blank?

  puts
  puts <<~EOS
    You have #{msg} installed.
    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

#select_formula_or_cask(key) ⇒ Object



566
567
568
# File 'cmd/update-report.rb', line 566

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