Class: Homebrew::Bundle::BrewInstaller Private
- Defined in:
- bundle/brew_installer.rb
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.
Class Method Summary collapse
- .formula_in_array?(formula, array) ⇒ Boolean private
- .formula_installed?(formula) ⇒ Boolean private
- .formula_installed_and_up_to_date?(formula, no_upgrade: false) ⇒ Boolean private
- .formula_upgradable?(formula) ⇒ Boolean private
- .formulae ⇒ Object private
- .install(name, preinstall: true, no_upgrade: false, verbose: false, force: false, **options) ⇒ Object private
- .installed_formulae ⇒ Object private
- .outdated_formulae ⇒ Object private
- .pinned_formulae ⇒ Object private
- .preinstall(name, no_upgrade: false, verbose: false, **options) ⇒ Object private
- .reset! ⇒ Object private
- .upgradable_formulae ⇒ Object private
Instance Method Summary collapse
- #changed? ⇒ Boolean private
-
#initialize(name, options = {}) ⇒ BrewInstaller
constructor
private
A new instance of BrewInstaller.
- #install(preinstall: true, no_upgrade: false, verbose: false, force: false) ⇒ Object private
- #install_change_state!(no_upgrade:, verbose:, force:) ⇒ Object private
- #link_change_state!(verbose: false) ⇒ Object private
- #postinstall_change_state!(verbose:) ⇒ Object private
- #preinstall(no_upgrade: false, verbose: false) ⇒ Object private
- #restart_service? ⇒ Boolean private
- #restart_service_needed? ⇒ Boolean private
- #service_change_state!(verbose:) ⇒ Object private
- #start_service? ⇒ Boolean private
- #start_service_needed? ⇒ Boolean private
Constructor Details
#initialize(name, options = {}) ⇒ BrewInstaller
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 a new instance of BrewInstaller.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'bundle/brew_installer.rb', line 21 def initialize(name, = {}) @full_name = name @name = name.split("/").last @args = .fetch(:args, []).map { |arg| "--#{arg}" } @conflicts_with_arg = .fetch(:conflicts_with, []) @restart_service = [:restart_service] @start_service = .fetch(:start_service, @restart_service) @link = .fetch(:link, nil) @postinstall = .fetch(:postinstall, nil) @version_file = .fetch(:version_file, nil) @changed = nil end |
Class Method Details
.formula_in_array?(formula, array) ⇒ 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.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'bundle/brew_installer.rb', line 175 def self.formula_in_array?(formula, array) return true if array.include?(formula) return true if array.include?(formula.split("/").last) require "bundle/brew_dumper" old_names = Homebrew::Bundle::BrewDumper.formula_oldnames old_name = old_names[formula] old_name ||= old_names[formula.split("/").last] return true if old_name && array.include?(old_name) resolved_full_name = Homebrew::Bundle::BrewDumper.formula_aliases[formula] return false unless resolved_full_name return true if array.include?(resolved_full_name) return true if array.include?(resolved_full_name.split("/").last) false end |
.formula_installed?(formula) ⇒ 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.
193 194 195 |
# File 'bundle/brew_installer.rb', line 193 def self.formula_installed?(formula) formula_in_array?(formula, installed_formulae) end |
.formula_installed_and_up_to_date?(formula, no_upgrade: false) ⇒ 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.
168 169 170 171 172 173 |
# File 'bundle/brew_installer.rb', line 168 def self.formula_installed_and_up_to_date?(formula, no_upgrade: false) return false unless formula_installed?(formula) return true if no_upgrade !formula_upgradable?(formula) end |
.formula_upgradable?(formula) ⇒ 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.
197 198 199 200 |
# File 'bundle/brew_installer.rb', line 197 def self.formula_upgradable?(formula) # Check local cache first and then authoritative Homebrew source. formula_in_array?(formula, upgradable_formulae) && Formula[formula].outdated? end |
.formulae ⇒ 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.
218 219 220 221 |
# File 'bundle/brew_installer.rb', line 218 def self.formulae require "bundle/brew_dumper" Homebrew::Bundle::BrewDumper.formulae end |
.install(name, preinstall: true, no_upgrade: false, verbose: false, force: false, **options) ⇒ 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.
17 18 19 |
# File 'bundle/brew_installer.rb', line 17 def self.install(name, preinstall: true, no_upgrade: false, verbose: false, force: false, **) new(name, ).install(preinstall:, no_upgrade:, verbose:, force:) end |
.installed_formulae ⇒ 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.
202 203 204 |
# File 'bundle/brew_installer.rb', line 202 def self.installed_formulae @installed_formulae ||= formulae.map { |f| f[:name] } end |
.outdated_formulae ⇒ 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.
210 211 212 |
# File 'bundle/brew_installer.rb', line 210 def self.outdated_formulae @outdated_formulae ||= formulae.filter_map { |f| f[:name] if f[:outdated?] } end |
.pinned_formulae ⇒ 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.
214 215 216 |
# File 'bundle/brew_installer.rb', line 214 def self.pinned_formulae @pinned_formulae ||= formulae.filter_map { |f| f[:name] if f[:pinned?] } end |
.preinstall(name, no_upgrade: false, verbose: false, **options) ⇒ 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 |
# File 'bundle/brew_installer.rb', line 13 def self.preinstall(name, no_upgrade: false, verbose: false, **) new(name, ).preinstall(no_upgrade:, verbose:) 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.
7 8 9 10 11 |
# File 'bundle/brew_installer.rb', line 7 def self.reset! @installed_formulae = nil @outdated_formulae = nil @pinned_formulae = nil end |
.upgradable_formulae ⇒ 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.
206 207 208 |
# File 'bundle/brew_installer.rb', line 206 def self.upgradable_formulae outdated_formulae - pinned_formulae 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.
110 111 112 |
# File 'bundle/brew_installer.rb', line 110 def changed? @changed.present? end |
#install(preinstall: true, no_upgrade: false, verbose: false, force: 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.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'bundle/brew_installer.rb', line 44 def install(preinstall: true, no_upgrade: false, verbose: false, force: false) install_result = if preinstall install_change_state!(no_upgrade:, verbose:, force:) else true end result = install_result if installed? service_result = service_change_state!(verbose:) result &&= service_result link_result = link_change_state!(verbose:) result &&= link_result postinstall_result = postinstall_change_state!(verbose:) result &&= postinstall_result if result && @version_file.present? # Use the version from the environment if it hasn't changed. # Strip the revision number because it's not part of the non-Homebrew version. version = if !changed? && (env_version = Bundle.formula_versions_from_env[@name]) PkgVersion.parse(env_version).version else Formula[@full_name].version end.to_s version_path = Pathname.new(@version_file) version_path.write("#{version}\n") puts "Wrote #{@name} version #{version} to #{@version_file}" if verbose end end result end |
#install_change_state!(no_upgrade:, verbose:, force:) ⇒ 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.
80 81 82 83 84 85 86 87 88 |
# File 'bundle/brew_installer.rb', line 80 def install_change_state!(no_upgrade:, verbose:, force:) return false unless resolve_conflicts!(verbose:) if installed? upgrade!(verbose:, force:) else install!(verbose:, force:) end end |
#link_change_state!(verbose: 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.
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 158 |
# File 'bundle/brew_installer.rb', line 130 def link_change_state!(verbose: false) link_args = [] link_args << "--force" if unlinked_and_keg_only? cmd = case @link when :overwrite link_args << "--overwrite" "link" unless linked? when true "link" unless linked? when false "unlink" if linked? when nil if keg_only? "unlink" if linked? else "link" unless linked? end end if cmd.present? verb = "#{cmd}ing".capitalize with_args = " with #{link_args.join(" ")}" if link_args.present? puts "#{verb} #{@name} formula#{with_args}." if verbose return Bundle.brew(cmd, *link_args, @name, verbose:) end true end |
#postinstall_change_state!(verbose:) ⇒ 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.
160 161 162 163 164 165 166 |
# File 'bundle/brew_installer.rb', line 160 def postinstall_change_state!(verbose:) return true if @postinstall.blank? return true unless changed? puts "Running postinstall for #{@name}: #{@postinstall}" if verbose Kernel.system(@postinstall) end |
#preinstall(no_upgrade: false, verbose: 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.
34 35 36 37 38 39 40 41 42 |
# File 'bundle/brew_installer.rb', line 34 def preinstall(no_upgrade: false, verbose: false) if installed? && (no_upgrade || !upgradable?) puts "Skipping install of #{@name} formula. It is already installed." if verbose @changed = nil return false end true end |
#restart_service? ⇒ 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.
99 100 101 |
# File 'bundle/brew_installer.rb', line 99 def restart_service? @restart_service.present? end |
#restart_service_needed? ⇒ 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.
103 104 105 106 107 108 |
# File 'bundle/brew_installer.rb', line 103 def restart_service_needed? return false unless restart_service? # Restart if `restart_service: :always`, or if the formula was installed or upgraded @restart_service.to_s == "always" || changed? end |
#service_change_state!(verbose:) ⇒ 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.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'bundle/brew_installer.rb', line 114 def service_change_state!(verbose:) require "bundle/brew_services" file = Bundle::BrewServices.versioned_service_file(@name) if restart_service_needed? puts "Restarting #{@name} service." if verbose BrewServices.restart(@full_name, file:, verbose:) elsif start_service_needed? puts "Starting #{@name} service." if verbose BrewServices.start(@full_name, file:, verbose:) else true end end |
#start_service? ⇒ 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.
90 91 92 |
# File 'bundle/brew_installer.rb', line 90 def start_service? @start_service.present? end |
#start_service_needed? ⇒ 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.
94 95 96 97 |
# File 'bundle/brew_installer.rb', line 94 def start_service_needed? require "bundle/brew_services" start_service? && !BrewServices.started?(@full_name) end |