Class: Homebrew::BundleVersion Private

Inherits:
Object
  • Object
show all
Extended by:
SystemCommand::Mixin
Includes:
Comparable
Defined in:
bundle_version.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.

Representation of a macOS bundle version, commonly found in Info.plist files.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SystemCommand::Mixin

system_command, system_command!

Constructor Details

#initialize(short_version, version) ⇒ 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.

Parameters:

Raises:

  • (ArgumentError)


50
51
52
53
54
55
56
57
58
59
60
# File 'bundle_version.rb', line 50

def initialize(short_version, version)
  # Remove version from short version, if present.
  short_version = short_version&.sub(/\s*\(#{Regexp.escape(version)}\)\Z/, "") if version

  @short_version = short_version.presence
  @version = version.presence

  return if @short_version || @version

  raise ArgumentError, "`short_version` and `version` cannot both be `nil` or empty"
end

Instance Attribute Details

#short_versionString? (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.

Returns:



47
48
49
# File 'bundle_version.rb', line 47

def short_version
  @short_version
end

#versionString? (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.

Returns:



47
48
49
# File 'bundle_version.rb', line 47

def version
  @version
end

Class Method Details

.from_info_plist(info_plist_path) ⇒ T.attached_class?

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.attached_class, nil)


14
15
16
17
# File 'bundle_version.rb', line 14

def self.from_info_plist(info_plist_path)
  plist = system_command!("plutil", args: ["-convert", "xml1", "-o", "-", info_plist_path]).plist
  from_info_plist_content(plist)
end

.from_info_plist_content(plist) ⇒ T.attached_class?

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.attached_class, nil)


20
21
22
23
24
25
# File 'bundle_version.rb', line 20

def self.from_info_plist_content(plist)
  short_version = plist["CFBundleShortVersionString"].presence
  version = plist["CFBundleVersion"].presence

  new(short_version, version) if short_version || version
end

.from_package_info(package_info_path) ⇒ T.attached_class?

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.attached_class, nil)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'bundle_version.rb', line 28

def self.from_package_info(package_info_path)
  require "rexml/document"

  xml = REXML::Document.new(package_info_path.read)

  bundle_version_bundle = xml.get_elements("//pkg-info//bundle-version//bundle").first
  bundle_id = bundle_version_bundle["id"] if bundle_version_bundle
  return if bundle_id.blank?

  bundle = xml.get_elements("//pkg-info//bundle").find { |b| b["id"] == bundle_id }
  return unless bundle

  short_version = bundle["CFBundleShortVersionString"]
  version = bundle["CFBundleVersion"]

  new(short_version, version) if short_version || version
end

Instance Method Details

#nice_versionString

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.

Create a nicely formatted version (on a best effort basis).

Returns:



90
91
92
# File 'bundle_version.rb', line 90

def nice_version
  nice_parts.join(",")
end