Class: Homebrew::Bundle::MacAppStore Private
- Inherits:
-
Extension
- Object
- PackageType
- Extension
- Homebrew::Bundle::MacAppStore
- Defined in:
- bundle/extensions/mac_app_store.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.
Defined Under Namespace
Constant Summary collapse
- CheckablePackages =
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.
T.type_alias { T.any(T::Array[Object], T::Hash[Integer, String]) }
Class Method Summary collapse
- .add_supported? ⇒ Boolean private
- .app_id_installed?(id) ⇒ Boolean private
- .app_id_installed_and_up_to_date?(id, no_upgrade: false) ⇒ Boolean private
- .app_id_upgradable?(id) ⇒ Boolean private
- .app_ids ⇒ Array<String> private
- .apps ⇒ Array<Array<(String, String)>> private
- .banner_name ⇒ String private
- .batch_installable?(_name, _options = {}) ⇒ Boolean private
- .check_label ⇒ String private
- .cleanup!(items) ⇒ void private
- .cleanup_heading ⇒ String? private
- .cleanup_item(app) ⇒ String private
- .cleanup_item_name(item) ⇒ String private
- .cleanup_items(entries) ⇒ Array<String> private
- .dump_entry(package) ⇒ String private
- .entry(name, options = {}) ⇒ Dsl::Entry private
- .install!(name, id = nil, with: nil, preinstall: true, no_upgrade: false, verbose: false, force: false, **options) ⇒ Boolean private
- .install_batch!(entries, verbose: false) ⇒ Boolean private
- .installed_app_ids ⇒ Array<String> private
- .installed_packages ⇒ Array<App> private
- .legacy_check_step ⇒ Symbol private
- .outdated_app_ids ⇒ Array<String> private
- .packages ⇒ Array<App> private
- .parse_cleanup_item(item) ⇒ App private
- .preinstall!(name, id = nil, with: nil, no_upgrade: false, verbose: false, **options) ⇒ Boolean private
- .reset! ⇒ void private
- .type ⇒ Symbol private
Instance Method Summary collapse
- #exit_early_check(packages, no_upgrade:) ⇒ Array<String> private
- #failure_reason(package, no_upgrade:) ⇒ String private
- #format_checkable(entries) ⇒ Array<Object> private
- #full_check(packages, no_upgrade:) ⇒ Array<String> private
- #installed_and_up_to_date?(package, no_upgrade: false) ⇒ Boolean private
Methods inherited from Extension
check, cleanup_disable_description, cleanup_disable_env, cleanup_supported?, disable_predicate_method, dump, dump_disable_description, dump_disable_env, dump_disable_predicate_method, dump_disable_supported?, dump_name, dump_output, dump_supported?, dump_with, ensure_package_manager_installed!, flag, inherited, install_package!, install_supported?, install_verb, package_description, package_installed?, package_manager_env, package_manager_executable, package_manager_executable!, package_manager_installed?, package_manager_name, package_record, predicate_method, quote, remove_supported?, switch_description, uninstall_package!, with_package_manager_env
Methods inherited from PackageType
check, #checkable_entries, dump, dump_output, dump_supported?, #find_actionable, inherited, install_supported?, install_verb
Class Method Details
.add_supported? ⇒ 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.
32 33 34 |
# File 'bundle/extensions/mac_app_store.rb', line 32 def add_supported? false end |
.app_id_installed?(id) ⇒ 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.
169 170 171 |
# File 'bundle/extensions/mac_app_store.rb', line 169 def app_id_installed?(id) installed_app_ids.any? { |app_id| app_id.to_i == id } end |
.app_id_installed_and_up_to_date?(id, 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.
179 180 181 182 183 184 |
# File 'bundle/extensions/mac_app_store.rb', line 179 def app_id_installed_and_up_to_date?(id, no_upgrade: false) return false unless app_id_installed?(id) return true if no_upgrade !app_id_upgradable?(id) end |
.app_id_upgradable?(id) ⇒ 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.
174 175 176 |
# File 'bundle/extensions/mac_app_store.rb', line 174 def app_id_upgradable?(id) outdated_app_ids.any? { |app_id| app_id.to_i == id } end |
.app_ids ⇒ 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.
102 103 104 |
# File 'bundle/extensions/mac_app_store.rb', line 102 def app_ids apps.map(&:first) end |
.apps ⇒ Array<Array<(String, 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.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'bundle/extensions/mac_app_store.rb', line 78 def apps apps = @apps return apps if apps @apps = if (mas = package_manager_executable) Utils.popen_read_text(mas, "list", err: File::NULL).split("\n").filter_map do |app| app_details = app.match(/\A\s*(?<id>\d+)\s+(?<name>.*?)\s+\(?(?<version>[\d.]*)\)?\Z/) next if app_details.nil? id = app_details[:id] name = app_details[:name] next if id.nil? || name.nil? # Only add the application details should we have a valid match. # Strip unprintable characters [id, name.gsub(/[[:cntrl:]]|\p{C}/, "")] end end return [] if @apps.nil? @apps end |
.banner_name ⇒ 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.
24 |
# File 'bundle/extensions/mac_app_store.rb', line 24 def = "Mac App Store dependencies" |
.batch_installable?(_name, _options = {}) ⇒ 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.
58 59 60 |
# File 'bundle/extensions/mac_app_store.rb', line 58 def batch_installable?(_name, = {}) true end |
.check_label ⇒ 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.
21 |
# File 'bundle/extensions/mac_app_store.rb', line 21 def check_label = "App" |
.cleanup!(items) ⇒ 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.
158 159 160 161 162 163 164 165 166 |
# File 'bundle/extensions/mac_app_store.rb', line 158 def cleanup!(items) mas = package_manager_executable return if mas.nil? items.each do |item| Bundle.system(mas, "uninstall", parse_cleanup_item(item).id, verbose: false) end puts "Uninstalled #{items.size} Mac App Store app#{"s" if items.size != 1}" end |
.cleanup_heading ⇒ 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.
37 38 39 |
# File 'bundle/extensions/mac_app_store.rb', line 37 def cleanup_heading "Mac App Store apps" end |
.cleanup_item(app) ⇒ 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.
134 135 136 |
# File 'bundle/extensions/mac_app_store.rb', line 134 def cleanup_item(app) JSON.generate("id" => app.id, "name" => app.name) end |
.cleanup_item_name(item) ⇒ 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.
139 140 141 142 |
# File 'bundle/extensions/mac_app_store.rb', line 139 def cleanup_item_name(item) app = parse_cleanup_item(item) "#{app.name} (#{app.id})" end |
.cleanup_items(entries) ⇒ 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.
145 146 147 148 149 150 151 152 153 154 155 |
# File 'bundle/extensions/mac_app_store.rb', line 145 def cleanup_items(entries) return [].freeze unless package_manager_installed? kept_app_ids = entries.filter_map do |entry| entry.[:id].to_s if entry.type == type end return [].freeze if kept_app_ids.empty? packages.reject { |app| app.id.to_i.zero? || kept_app_ids.any? { |id| app.id.to_i == id.to_i } } .map { |app| cleanup_item(app) } end |
.dump_entry(package) ⇒ 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.
128 129 130 131 |
# File 'bundle/extensions/mac_app_store.rb', line 128 def dump_entry(package) app = T.cast(package, App) "mas #{quote(app.name)}, id: #{app.id}" end |
.entry(name, options = {}) ⇒ Dsl::Entry
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.
42 43 44 45 46 47 |
# File 'bundle/extensions/mac_app_store.rb', line 42 def entry(name, = {}) id = [:id] raise "options[:id](#{id}) should be an Integer object" unless id.is_a? Integer Dsl::Entry.new(type, name, id:) end |
.install!(name, id = nil, with: nil, preinstall: true, no_upgrade: false, verbose: false, force: false, **options) ⇒ 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.
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'bundle/extensions/mac_app_store.rb', line 243 def install!(name, id = nil, with: nil, preinstall: true, no_upgrade: false, verbose: false, force: false, **) _ = with id ||= T.cast([:id], T.nilable(Integer)) raise ArgumentError, "missing keyword: id" if id.nil? _ = no_upgrade _ = force return true unless preinstall mas = package_manager_executable! if app_id_installed?(id) puts "Upgrading #{name} app. It is installed but not up-to-date." if verbose return false unless Bundle.system(mas, "upgrade", id.to_s, verbose:) return true end puts "Installing #{name} app. It is not currently installed." if verbose installed = Bundle.system(mas, "install", id.to_s, verbose:) || Bundle.system(mas, "get", id.to_s, verbose:) return false unless installed apps << [id.to_s, name] unless apps.any? { |app_id, _app_name| app_id.to_i == id } packages << App.new(id: id.to_s, name:) unless packages.any? { |app| app.id.to_i == id } installed_app_ids << id.to_s unless installed_app_ids.include?(id.to_s) true end |
.install_batch!(entries, verbose: 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.
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'bundle/extensions/mac_app_store.rb', line 63 def install_batch!(entries, verbose: false) outdated_entries, fresh_entries = entries.partition do |entry| app_id_installed?(T.cast(entry..fetch(:id), Integer)) end mas = package_manager_executable! upgraded = outdated_entries.empty? || Bundle.system( mas, "upgrade", *outdated_entries.map { |entry| entry..fetch(:id).to_s }, verbose: ) fresh_installed = fresh_entries.empty? || Bundle.system( mas, "install", *fresh_entries.map { |entry| entry..fetch(:id).to_s }, verbose: ) || Bundle.system(mas, "get", *fresh_entries.map { |entry| entry..fetch(:id).to_s }, verbose:) upgraded && fresh_installed end |
.installed_app_ids ⇒ 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.
120 121 122 123 124 125 |
# File 'bundle/extensions/mac_app_store.rb', line 120 def installed_app_ids installed_app_ids = @installed_app_ids return installed_app_ids if installed_app_ids @installed_app_ids = app_ids end |
.installed_packages ⇒ Array<App>
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.
115 116 117 |
# File 'bundle/extensions/mac_app_store.rb', line 115 def installed_packages packages end |
.legacy_check_step ⇒ Symbol
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.
27 28 29 |
# File 'bundle/extensions/mac_app_store.rb', line 27 def legacy_check_step :apps_to_install end |
.outdated_app_ids ⇒ 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.
187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'bundle/extensions/mac_app_store.rb', line 187 def outdated_app_ids outdated_app_ids = @outdated_app_ids return outdated_app_ids if outdated_app_ids @outdated_app_ids = if (mas = package_manager_executable) Utils.popen_read_text(mas, "outdated", err: File::NULL).split("\n").map do |app| app.split(" ", 2).first.to_s end end return [] if @outdated_app_ids.nil? @outdated_app_ids end |
.packages ⇒ Array<App>
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.
107 108 109 110 111 112 |
# File 'bundle/extensions/mac_app_store.rb', line 107 def packages packages = @packages return packages if packages @packages = apps.sort_by { |_, name| name.downcase }.map { |id, name| App.new(id:, name:) } end |
.parse_cleanup_item(item) ⇒ App
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.
275 276 277 278 279 280 281 282 283 284 |
# File 'bundle/extensions/mac_app_store.rb', line 275 def parse_cleanup_item(item) parsed = JSON.parse(item) raise TypeError, "Invalid Mac App Store cleanup item: #{item}" unless parsed.is_a?(Hash) id = parsed["id"] name = parsed["name"] raise TypeError, "Invalid Mac App Store cleanup item: #{item}" if !id.is_a?(String) || !name.is_a?(String) App.new(id:, name:) end |
.preinstall!(name, id = nil, with: nil, no_upgrade: false, verbose: false, **options) ⇒ 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.
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'bundle/extensions/mac_app_store.rb', line 211 def preinstall!(name, id = nil, with: nil, no_upgrade: false, verbose: false, **) _ = with id ||= T.cast([:id], T.nilable(Integer)) raise ArgumentError, "missing keyword: id" if id.nil? unless package_manager_installed? puts "Installing mas. It is not currently installed." if verbose Bundle.system(HOMEBREW_BREW_FILE, "install", "mas", verbose:) raise "Unable to install #{name} app. mas installation failed." unless package_manager_installed? end if app_id_installed?(id) && (no_upgrade || !app_id_upgradable?(id)) puts "Skipping install of #{name} app. It is already installed." if verbose return false end true end |
.reset! ⇒ 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.
50 51 52 53 54 55 |
# File 'bundle/extensions/mac_app_store.rb', line 50 def reset! @apps = T.let(nil, T.nilable(T::Array[[String, String]])) @packages = T.let(nil, T.nilable(T::Array[App])) @installed_app_ids = T.let(nil, T.nilable(T::Array[String])) @outdated_app_ids = T.let(nil, T.nilable(T::Array[String])) end |
.type ⇒ Symbol
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.
18 |
# File 'bundle/extensions/mac_app_store.rb', line 18 def type = :mas |
Instance Method Details
#exit_early_check(packages, no_upgrade:) ⇒ 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.
295 296 297 298 299 300 301 302 |
# File 'bundle/extensions/mac_app_store.rb', line 295 def exit_early_check(packages, no_upgrade:) (packages.is_a?(Hash) ? packages.to_a : packages).each do |id, name| next if installed_and_up_to_date?(id, no_upgrade:) return [failure_reason(name, no_upgrade:)] end [] end |
#failure_reason(package, no_upgrade:) ⇒ 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.
312 313 314 315 |
# File 'bundle/extensions/mac_app_store.rb', line 312 def failure_reason(package, no_upgrade:) reason = no_upgrade ? "needs to be installed." : "needs to be installed or updated." "#{self.class.check_label} #{package} #{reason}" end |
#format_checkable(entries) ⇒ Array<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.
288 289 290 291 292 |
# File 'bundle/extensions/mac_app_store.rb', line 288 def format_checkable(entries) checkable_entries(entries).map do |entry| [T.cast(entry..fetch(:id), Integer), entry.name] end end |
#full_check(packages, no_upgrade:) ⇒ 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.
305 306 307 308 309 |
# File 'bundle/extensions/mac_app_store.rb', line 305 def full_check(packages, no_upgrade:) (packages.is_a?(Hash) ? packages.to_a : packages) .reject { |id, _name| installed_and_up_to_date?(id, no_upgrade:) } .map { |_id, name| failure_reason(name, no_upgrade:) } end |
#installed_and_up_to_date?(package, 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.
318 319 320 |
# File 'bundle/extensions/mac_app_store.rb', line 318 def installed_and_up_to_date?(package, no_upgrade: false) self.class.app_id_installed_and_up_to_date?(T.cast(package, Integer), no_upgrade:) end |