Module: Homebrew::Bundle::MacAppStoreDumper Private

Defined in:
bundle/mac_app_store_dumper.rb

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.

Class Method Summary collapse

Class Method Details

.app_idsObject

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.



30
31
32
# File 'bundle/mac_app_store_dumper.rb', line 30

def self.app_ids
  apps.map { |id, _| id.to_i }
end

.appsObject

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
23
24
25
26
27
28
# File 'bundle/mac_app_store_dumper.rb', line 13

def self.apps
  @apps ||= if Bundle.mas_installed?
    `mas list 2>/dev/null`.split("\n").map do |app|
      app_details = app.match(/\A(?<id>\d+)\s+(?<name>.*?)\s+\((?<version>[\d.]*)\)\Z/)

      # Only add the application details should we have a valid match.
      # Strip unprintable characters
      if app_details
        name = T.must(app_details[:name])
        [app_details[:id], name.gsub(/[[:cntrl:]]|[\p{C}]/, "")]
      end
    end
  else
    []
  end.compact
end

.dumpObject

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
# File 'bundle/mac_app_store_dumper.rb', line 34

def self.dump
  apps.sort_by { |_, name| name.downcase }.map { |id, name| "mas \"#{name}\", id: #{id}" }.join("\n")
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.



9
10
11
# File 'bundle/mac_app_store_dumper.rb', line 9

def self.reset!
  @apps = nil
end