Class: Homebrew::BundleVersion Private

Inherits:
Object
  • Object
show all
Extended by:
SystemCommand::Mixin, T::Sig
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)


54
55
56
57
58
59
60
61
# File 'bundle_version.rb', line 54

def initialize(short_version, 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:



51
52
53
# File 'bundle_version.rb', line 51

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:



51
52
53
# File 'bundle_version.rb', line 51

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)


18
19
20
21
# File 'bundle_version.rb', line 18

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:

  • plist (Hash{String => T.untyped})

Returns:

  • (T.attached_class, nil)


24
25
26
27
28
29
# File 'bundle_version.rb', line 24

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)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'bundle_version.rb', line 32

def self.from_package_info(package_info_path)
  Homebrew.install_bundler_gems!
  require "nokogiri"

  xml = Nokogiri::XML(package_info_path.read)

  bundle_id = xml.xpath("//pkg-info//bundle-version//bundle").first&.attr("id")
  return unless bundle_id

  bundle = xml.xpath("//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

#<=>(other) ⇒ 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.



63
64
65
66
# File 'bundle_version.rb', line 63

def <=>(other)
  [version, short_version].map { |v| v&.yield_self(&Version.public_method(:new)) || Version::NULL } <=>
    [other.version, other.short_version].map { |v| v&.yield_self(&Version.public_method(:new)) || Version::NULL }
end

#==(other) ⇒ Object Also known as: eql?

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.



68
69
70
# File 'bundle_version.rb', line 68

def ==(other)
  instance_of?(other.class) && short_version == other.short_version && version == other.version
end

#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:



75
76
77
# File 'bundle_version.rb', line 75

def nice_version
  nice_parts.join(",")
end