Class: Homebrew::BundleVersion Private
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
- #short_version ⇒ String? readonly private
- #version ⇒ String? readonly private
Class Method Summary collapse
- .from_info_plist(info_plist_path) ⇒ T.attached_class? private
- .from_info_plist_content(plist) ⇒ T.attached_class? private
- .from_package_info(package_info_path) ⇒ T.attached_class? private
Instance Method Summary collapse
- #initialize(short_version, version) ⇒ void constructor private
-
#nice_version ⇒ String
private
Create a nicely formatted version (on a best effort basis).
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.
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_version ⇒ String? (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.
47 48 49 |
# File 'bundle_version.rb', line 47 def short_version @short_version end |
#version ⇒ String? (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.
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.
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.
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.
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_version ⇒ 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.
Create a nicely formatted version (on a best effort basis).
92 93 94 |
# File 'bundle_version.rb', line 92 def nice_version nice_parts.join(",") end |