Module: Homebrew::Bundle::BrewDumper Private

Defined in:
bundle/brew_dumper.rb

Overview

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

TODO:

refactor into multiple modules

Defined Under Namespace

Classes: Topo

Class Method Summary collapse

Class Method Details

.dump(describe: false, no_restart: false) ⇒ Object

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.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'bundle/brew_dumper.rb', line 58

def dump(describe: false, no_restart: false)
  require "bundle/brew_services"

  requested_formula = formulae.select do |f|
    f[:installed_on_request?] || !f[:installed_as_dependency?]
  end
  requested_formula.map do |f|
    brewline = if describe && f[:desc].present?
      f[:desc].split("\n").map { |s| "# #{s}\n" }.join
    else
      ""
    end
    brewline += "brew \"#{f[:full_name]}\""

    args = f[:args].map { |arg| "\"#{arg}\"" }.sort.join(", ")
    brewline += ", args: [#{args}]" unless f[:args].empty?
    brewline += ", restart_service: :changed" if !no_restart && BrewServices.started?(f[:full_name])
    brewline += ", link: #{f[:link?]}" unless f[:link?].nil?
    brewline
  end.join("\n")
end

.formula_aliasesObject

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.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'bundle/brew_dumper.rb', line 80

def formula_aliases
  return @formula_aliases if @formula_aliases

  @formula_aliases = {}
  formulae.each do |f|
    aliases = f[:aliases]
    next if aliases.blank?

    aliases.each do |a|
      @formula_aliases[a] = f[:full_name]
      if f[:full_name].include? "/" # tap formula
        tap_name = f[:full_name].rpartition("/").first
        @formula_aliases["#{tap_name}/#{a}"] = f[:full_name]
      end
    end
  end
  @formula_aliases
end

.formula_oldnamesObject

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.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'bundle/brew_dumper.rb', line 99

def formula_oldnames
  return @formula_oldnames if @formula_oldnames

  @formula_oldnames = {}
  formulae.each do |f|
    oldnames = f[:oldnames]
    next if oldnames.blank?

    oldnames.each do |oldname|
      @formula_oldnames[oldname] = f[:full_name]
      if f[:full_name].include? "/" # tap formula
        tap_name = f[:full_name].rpartition("/").first
        @formula_oldnames["#{tap_name}/#{oldname}"] = f[:full_name]
      end
    end
  end
  @formula_oldnames
end

.formulaeObject

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.



24
25
26
27
28
29
# File 'bundle/brew_dumper.rb', line 24

def formulae
  return @formulae if @formulae

  formulae_by_full_name
  @formulae
end

.formulae_by_full_name(name = nil) ⇒ Object

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.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'bundle/brew_dumper.rb', line 31

def formulae_by_full_name(name = nil)
  return @formulae_by_full_name[name] if name.present? && @formulae_by_full_name&.key?(name)

  require "formula"
  require "formulary"
  Formulary.enable_factory_cache!

  @formulae_by_name ||= {}
  @formulae_by_full_name ||= {}

  if name.nil?
    formulae = Formula.installed.map(&method(:add_formula))
    sort!(formulae)
    return @formulae_by_full_name
  end

  formula = Formula[name]
  add_formula(formula)
rescue FormulaUnavailableError => e
  opoo "'#{name}' formula is unreadable: #{e}"
  {}
end

.formulae_by_name(name) ⇒ Object

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.



54
55
56
# File 'bundle/brew_dumper.rb', line 54

def formulae_by_name(name)
  formulae_by_full_name(name) || @formulae_by_name[name]
end

.reset!Object

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
17
18
19
20
21
22
# File 'bundle/brew_dumper.rb', line 13

def reset!
  require "bundle/brew_services"

  Homebrew::Bundle::BrewServices.reset!
  @formulae = nil
  @formulae_by_full_name = nil
  @formulae_by_name = nil
  @formula_aliases = nil
  @formula_oldnames = nil
end