lib/run_loop/app.rb in run_loop-2.1.0.pre1 vs lib/run_loop/app.rb in run_loop-2.1.0

- old
+ new

@@ -31,11 +31,24 @@ end end # @!visibility private def to_s - "#<APP: #{path}>" + cf_bundle_version = bundle_version + cf_bundle_short_version = short_bundle_version + + if cf_bundle_version && cf_bundle_short_version + version = "#{cf_bundle_version.to_s} / #{cf_bundle_short_version}" + elsif cf_bundle_version + version = cf_bundle_version.to_s + elsif cf_bundle_short_version + version = cf_bundle_short_version + else + version = "" + end + + "#<APP #{bundle_identifier} #{version} #{path}>" end # @!visibility private def inspect to_s @@ -127,9 +140,78 @@ # @!visibility private def distribution_signed? RunLoop::Codesign.distribution?(path) end + + # Returns the CFBundleShortVersionString of the app as Version instance. + # + # Apple docs: + # + # CFBundleShortVersionString specifies the release version number of the + # bundle, which identifies a released iteration of the app. The release + # version number is a string comprised of three period-separated integers. + # + # The first integer represents major revisions to the app, such as revisions + # that implement new features or major changes. The second integer denotes + # revisions that implement less prominent features. The third integer + # represents maintenance releases. + # + # The value for this key differs from the value for CFBundleVersion, which + # identifies an iteration (released or unreleased) of the app. This key can + # be localized by including it in your InfoPlist.strings files. + # + # @return [RunLoop::Version, nil] Returns a Version instance if the + # CFBundleShortVersion string is well formed and nil if not. + def marketing_version + string = plist_buddy.plist_read("CFBundleShortVersionString", info_plist_path) + begin + version = RunLoop::Version.new(string) + rescue + if string && string != "" + RunLoop.log_debug("CFBundleShortVersionString: '#{string}' is not a well formed version string") + else + RunLoop.log_debug("CFBundleShortVersionString is not defined in Info.plist") + end + version = nil + end + version + end + + # See #marketing_version + alias_method :short_bundle_version, :marketing_version + + # Returns the CFBundleVersionString of the app as Version instance. + # + # Apple docs: + # + # CFBundleVersion specifies the build version number of the bundle, which + # identifies an iteration (released or unreleased) of the bundle. The build + # version number should be a string comprised of three non-negative, + # period-separated integers with the first integer being greater than zero. + # The string should only contain numeric (0-9) and period (.) characters. + # Leading zeros are truncated from each integer and will be ignored (that + # is, 1.02.3 is equivalent to 1.2.3). + # + # @return [RunLoop::Version, nil] Returns a Version instance if the + # CFBundleVersion string is well formed and nil if not. + def build_version + string = plist_buddy.plist_read("CFBundleVersionString", info_plist_path) + begin + version = RunLoop::Version.new(string) + rescue + if string && string != "" + RunLoop.log_debug("CFBundleVersionString: '#{string}' is not a well formed version string") + else + RunLoop.log_debug("CFBundleVersionString is not defined in Info.plist") + end + version = nil + end + version + end + + # See #build_version + alias_method :bundle_version, :build_version # @!visibility private # Collects the paths to executables in the bundle. def executables executables = []