Class: Homebrew::BundleVersion Private

Inherits:
Object
  • Object
show all
Extended by:
SystemCommand::Mixin, T::Sig
Defined in:
brew/Library/Homebrew/bundle_version.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

Raises:

  • (ArgumentError)


48
49
50
51
52
53
54
55
# File 'brew/Library/Homebrew/bundle_version.rb', line 48

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. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



45
46
47
# File 'brew/Library/Homebrew/bundle_version.rb', line 45

def short_version
  @short_version
end

#versionString? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



45
46
47
# File 'brew/Library/Homebrew/bundle_version.rb', line 45

def version
  @version
end

Class Method Details

.from_info_plist(info_plist_path) ⇒ T.attached_class?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

Returns:

  • (T.attached_class, nil)


16
17
18
19
20
21
22
23
# File 'brew/Library/Homebrew/bundle_version.rb', line 16

def self.from_info_plist(info_plist_path)
  plist = system_command!("plutil", args: ["-convert", "xml1", "-o", "-", info_plist_path]).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. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

Returns:

  • (T.attached_class, nil)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'brew/Library/Homebrew/bundle_version.rb', line 26

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. You should avoid using this method if possible, as it may be removed or be changed in the future.



57
58
59
60
# File 'brew/Library/Homebrew/bundle_version.rb', line 57

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

#nice_versionString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Returns:



64
65
66
# File 'brew/Library/Homebrew/bundle_version.rb', line 64

def nice_version
  nice_parts.join(",")
end