Class: Homebrew::ExecutablesDB Private
- Includes:
- Utils::Output::Mixin
- Defined in:
- executables_db.rb
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
ExecutablesDB represents a DB associating formulae to the binaries they provide.
Defined Under Namespace
Classes: Changes, FormulaEntry
Constant Summary collapse
- DB_LINE_REGEX =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
/^(?<name>.*?)(?:\((?<version>.*)\)):(?<exes_line>.*)?$/
Instance Attribute Summary collapse
- #changes ⇒ Changes readonly private
- #exes ⇒ Hash{String => FormulaEntry} private
- #root ⇒ Pathname readonly private
Instance Method Summary collapse
- #changed? ⇒ Boolean private
- #formula_names ⇒ Array<String> private
-
#initialize(filename) ⇒ void
constructor
private
initialize a new DB with the given filename.
-
#save! ⇒ void
private
save the DB in the underlying file.
-
#update!(update_existing: false, install_missing: false, max_downloads: nil, eval_all: false) ⇒ void
private
update the DB with the installed formulae.
Methods included from Utils::Output::Mixin
#odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #pretty_duration, #pretty_installed, #pretty_outdated, #pretty_uninstalled
Constructor Details
#initialize(filename) ⇒ 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.
initialize a new DB with the given filename. The file will be used to populate the DB if it exists. It'll be created or overridden when saving the DB.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'executables_db.rb', line 59 def initialize(filename) @filename = filename @root = T.let(Pathname.new(@filename).parent, Pathname) @exes = T.let({}, T::Hash[String, FormulaEntry]) # keeps track of things that changed in the DB between its creation and # each {#save!} call. This is used to generate commit messages @changes = T.let(Changes.new, Changes) return unless File.file? @filename File.new(@filename).each do |line| matches = line.match DB_LINE_REGEX next unless matches name = T.must(matches[:name]) version = T.must(matches[:version]) binaries = matches[:exes_line]&.split || [] @exes[name] ||= FormulaEntry.new(version:, binaries:) end end |
Instance Attribute Details
#changes ⇒ Changes (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.
22 23 24 |
# File 'executables_db.rb', line 22 def changes @changes end |
#exes ⇒ Hash{String => FormulaEntry}
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.
19 20 21 |
# File 'executables_db.rb', line 19 def exes @exes end |
#root ⇒ Pathname (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.
25 26 27 |
# File 'executables_db.rb', line 25 def root @root end |
Instance Method Details
#changed? ⇒ 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.
87 88 89 |
# File 'executables_db.rb', line 87 def changed? @changes.changed? end |
#formula_names ⇒ Array<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.
82 83 84 |
# File 'executables_db.rb', line 82 def formula_names @exes.keys end |
#save! ⇒ 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.
save the DB in the underlying file
161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'executables_db.rb', line 161 def save! ordered_db = @exes.map do |formula, entry| version_string = "(#{entry.version})" "#{formula}#{version_string}:#{entry.binaries.join(" ")}\n" end.sort File.open(@filename, "w") do |f| ordered_db.each do |line| f.write(line) end end end |
#update!(update_existing: false, install_missing: false, max_downloads: nil, eval_all: 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.
update the DB with the installed formulae
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'executables_db.rb', line 101 def update!(update_existing: false, install_missing: false, max_downloads: nil, eval_all: false) downloads = 0 disabled_formulae = [] # Evaluate only the core tap by default. taps = eval_all ? Tap.each.to_a : [CoreTap.instance] taps.each do |tap| tap.formula_files_by_name.each_key do |name| f = Formulary.factory("#{tap}/#{name}") break if max_downloads.present? && downloads > max_downloads.to_i name = f.full_name if f.disabled? disabled_formulae << name next end update_formula = missing_formula?(f) || (update_existing && outdated_formula?(f)) # Install unbottled formulae if they should be added/updated if !f.bottled? && install_missing && update_formula downloads += 1 ohai "Installing #{f}" system HOMEBREW_BREW_FILE, "install", "--formula", f.to_s end # We don't need to worry about updating outdated versions unless update_existing is true if f.latest_version_installed? update_installed_formula f elsif f.bottled? && update_formula downloads += 1 update_bottled_formula f end # renamed formulae f.oldnames.each do |oldname| mv oldname, name if @exes[oldname] end # aliased formulae f.aliases.each do |a| mv a, name if @exes[a] end end end removed = (@exes.keys - Formula.full_names) | disabled_formulae removed.each do |name| next unless @exes.key?(name) @exes.delete name @changes.remove << name end nil end |