Class: Homebrew::Bundle::MacAppStore Private

Inherits:
Extension show all
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.

Constant Summary collapse

App =

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 { { id: String, name: String } }
PACKAGE_TYPE =

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.

:mas
PACKAGE_TYPE_NAME =

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.

"App"
"Mac App Store dependencies"

Constants inherited from Extension

Extension::EntryOptions

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Extension

banner_name, check, check_label, cleanup!, cleanup_heading, cleanup_items, cleanup_supported?, dump, dump_disable_description, dump_disable_env, dump_disable_predicate_method, dump_name, dump_supported?, dump_with, flag, inherited, install_package!, install_supported?, legacy_cleanup_method, package_description, package_installed?, package_manager_executable, package_manager_installed?, package_manager_name, package_record, predicate_method, quote, remove_supported?, switch_description, type

Methods inherited from Checker::Base

#checkable_entries, #find_actionable

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.

Returns:

  • (Boolean)


17
18
19
# File 'bundle/extensions/mac_app_store.rb', line 17

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.

Parameters:

Returns:

  • (Boolean)


101
102
103
# File 'bundle/extensions/mac_app_store.rb', line 101

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.

Parameters:

  • id (Integer)
  • no_upgrade (Boolean) (defaults to: false)

Returns:

  • (Boolean)


111
112
113
114
115
116
# File 'bundle/extensions/mac_app_store.rb', line 111

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.

Parameters:

Returns:

  • (Boolean)


106
107
108
# File 'bundle/extensions/mac_app_store.rb', line 106

def app_id_upgradable?(id)
  outdated_app_ids.any? { |app_id| app_id.to_i == id }
end

.app_idsArray<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.

Returns:



69
70
71
# File 'bundle/extensions/mac_app_store.rb', line 69

def app_ids
  apps.map(&:first)
end

.appsArray<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.

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'bundle/extensions/mac_app_store.rb', line 43

def apps
  apps = @apps
  return apps if apps

  @apps = if Bundle.mas_installed?
    mas = Bundle.which_mas
    return [] if mas.nil?

    `#{mas} list 2>/dev/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
  else
    []
  end
end

.dump_disable_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.

Returns:

  • (Boolean)


22
23
24
# File 'bundle/extensions/mac_app_store.rb', line 22

def dump_disable_supported?
  false
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.

Parameters:

Returns:



95
96
97
98
# File 'bundle/extensions/mac_app_store.rb', line 95

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.

Parameters:

Returns:



27
28
29
30
31
32
# File 'bundle/extensions/mac_app_store.rb', line 27

def entry(name, options = {})
  id = options[: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.

Parameters:

  • name (String)
  • id (Integer, nil) (defaults to: nil)
  • with (Array<String>, nil) (defaults to: nil)
  • preinstall (Boolean) (defaults to: true)
  • no_upgrade (Boolean) (defaults to: false)
  • verbose (Boolean) (defaults to: false)
  • force (Boolean) (defaults to: false)
  • options (Object)

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'bundle/extensions/mac_app_store.rb', line 177

def install!(name, id = nil, with: nil, preinstall: true, no_upgrade: false, verbose: false, force: false,
             **options)
  _ = with
  id ||= T.cast(options[:id], T.nilable(Integer))
  raise ArgumentError, "missing keyword: id" if id.nil?

  _ = no_upgrade
  _ = force

  return true unless preinstall

  mas = Bundle.which_mas
  return false if mas.nil?

  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
  return false unless Bundle.system(mas, "get", id.to_s, verbose:)

  apps << [id.to_s, name] unless apps.any? { |app_id, _app_name| app_id.to_i == id }
  packages << { 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

.installed_app_idsArray<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.

Returns:



87
88
89
90
91
92
# File 'bundle/extensions/mac_app_store.rb', line 87

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_packagesArray<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.

Returns:



82
83
84
# File 'bundle/extensions/mac_app_store.rb', line 82

def installed_packages
  packages
end

.outdated_app_idsArray<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.

Returns:



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'bundle/extensions/mac_app_store.rb', line 119

def outdated_app_ids
  outdated_app_ids = @outdated_app_ids
  return outdated_app_ids if outdated_app_ids

  @outdated_app_ids = if Bundle.mas_installed?
    mas = Bundle.which_mas
    return [] if mas.nil?

    `#{mas} outdated 2>/dev/null`.split("\n").map do |app|
      app.split(" ", 2).first.to_s
    end
  else
    []
  end
end

.packagesArray<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.

Returns:



74
75
76
77
78
79
# File 'bundle/extensions/mac_app_store.rb', line 74

def packages
  packages = @packages
  return packages if packages

  @packages = apps.sort_by { |_, name| name.downcase }.map { |id, name| { 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.

Parameters:

  • name (String)
  • id (Integer, nil) (defaults to: nil)
  • with (Array<String>, nil) (defaults to: nil)
  • no_upgrade (Boolean) (defaults to: false)
  • verbose (Boolean) (defaults to: false)
  • options (Object)

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'bundle/extensions/mac_app_store.rb', line 145

def preinstall!(name, id = nil, with: nil, no_upgrade: false, verbose: false, **options)
  _ = with
  id ||= T.cast(options[:id], T.nilable(Integer))
  raise ArgumentError, "missing keyword: id" if id.nil?

  unless Bundle.mas_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 Bundle.mas_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.



35
36
37
38
39
40
# File 'bundle/extensions/mac_app_store.rb', line 35

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

Instance Method Details

#exit_early_check(packages, no_upgrade:) ⇒ Array<T.untyped>

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.

Parameters:

  • packages (T.untyped)
  • no_upgrade (Boolean)

Returns:



217
218
219
220
221
222
223
# File 'bundle/extensions/mac_app_store.rb', line 217

def exit_early_check(packages, no_upgrade:)
  work_to_be_done = packages.find do |id, _name|
    !installed_and_up_to_date?(id, no_upgrade:)
  end

  Array(work_to_be_done)
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.

Parameters:

  • package (Object)
  • no_upgrade (Boolean)

Returns:



232
233
234
235
# File 'bundle/extensions/mac_app_store.rb', line 232

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) ⇒ T.untyped

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.

Parameters:

Returns:

  • (T.untyped)


209
210
211
212
213
214
# File 'bundle/extensions/mac_app_store.rb', line 209

def format_checkable(entries)
  checkable_entries(entries).to_h do |entry|
    entry = T.cast(entry, Dsl::Entry)
    [T.cast(entry.options.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.

Parameters:

  • packages (T.untyped)
  • no_upgrade (Boolean)

Returns:



226
227
228
229
# File 'bundle/extensions/mac_app_store.rb', line 226

def full_check(packages, no_upgrade:)
  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.

Parameters:

  • package (Object)
  • no_upgrade (Boolean) (defaults to: false)

Returns:

  • (Boolean)


238
239
240
# File 'bundle/extensions/mac_app_store.rb', line 238

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