Class: RunLoop::App
- Inherits:
-
Object
- Object
- RunLoop::App
- Defined in:
- lib/run_loop/app.rb
Overview
A class for interacting with .app bundles.
Instance Attribute Summary collapse
-
#path ⇒ String
readonly
The path to the app bundle .app.
Instance Method Summary collapse
-
#arches ⇒ Object
Returns the arches for the binary.
-
#build_version ⇒ RunLoop::Version?
(also: #bundle_version)
Returns the CFBundleVersion of the app as Version instance.
-
#bundle_identifier ⇒ String
Inspects the app’s Info.plist for the bundle identifier.
-
#calabash_server_version ⇒ Object
Inspects the app’s file for the server version.
-
#executable_name ⇒ String
Inspects the app’s Info.plist for the executable name.
-
#info_plist_path ⇒ Object
Returns the Info.plist path.
-
#initialize(app_bundle_path) ⇒ RunLoop::App
constructor
Creates a new App instance.
-
#marketing_version ⇒ RunLoop::Version?
(also: #short_bundle_version)
Returns the CFBundleShortVersionString of the app as Version instance.
-
#physical_device? ⇒ Boolean
True if the app has been built for physical devices.
-
#sha1 ⇒ Object
Returns the sha1 of the application.
-
#simulator? ⇒ Boolean
True if the app has been built for the simulator.
-
#valid? ⇒ Boolean
Is this a valid app?.
Constructor Details
#initialize(app_bundle_path) ⇒ RunLoop::App
The ‘app_bundle_path` is expanded during initialization.
Creates a new App instance.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/run_loop/app.rb', line 15 def initialize(app_bundle_path) @path = File.(app_bundle_path) if !App.valid?(app_bundle_path) if App.cached_app_on_simulator?(app_bundle_path) raise RuntimeError, %Q{ App is "cached" on the simulator. #{app_bundle_path} This can happen if there was an incomplete install or uninstall. Try manually deleting the application data container and relaunching the simulator. $ rm -r #{File.dirname(app_bundle_path)} $ run-loop simctl manage-processes } else raise ArgumentError, %Q{App does not exist at path or is not an app bundle. #{app_bundle_path} Bundle must: 1. be a directory that exists, 2. have a .app extension, 3. contain an Info.plist, 4. and the app binary (CFBundleExecutable) must exist } end end end |
Instance Attribute Details
#path ⇒ String (readonly)
Returns The path to the app bundle .app.
7 8 9 |
# File 'lib/run_loop/app.rb', line 7 def path @path end |
Instance Method Details
#arches ⇒ Object
Returns the arches for the binary.
133 134 135 |
# File 'lib/run_loop/app.rb', line 133 def arches @arches ||= lipo.info end |
#build_version ⇒ RunLoop::Version? Also known as: bundle_version
Returns the CFBundleVersion 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).
233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/run_loop/app.rb', line 233 def build_version string = plist_buddy.plist_read("CFBundleVersion", info_plist_path) begin version = RunLoop::Version.new(string) rescue if string && string != "" RunLoop.log_debug("CFBundleVersion: '#{string}' is not a well formed version string") else RunLoop.log_debug("CFBundleVersion is not defined in Info.plist") end version = nil end version end |
#bundle_identifier ⇒ String
Inspects the app’s Info.plist for the bundle identifier.
112 113 114 115 116 117 118 |
# File 'lib/run_loop/app.rb', line 112 def bundle_identifier identifier = plist_buddy.plist_read("CFBundleIdentifier", info_plist_path) unless identifier raise "Expected key 'CFBundleIdentifier' in '#{info_plist_path}'" end identifier end |
#calabash_server_version ⇒ Object
Inspects the app’s file for the server version
150 151 152 153 154 155 156 157 |
# File 'lib/run_loop/app.rb', line 150 def calabash_server_version version = nil executables.each do |executable| version = strings(executable).server_version break if version end version end |
#executable_name ⇒ String
Inspects the app’s Info.plist for the executable name.
124 125 126 127 128 129 130 |
# File 'lib/run_loop/app.rb', line 124 def executable_name name = plist_buddy.plist_read("CFBundleExecutable", info_plist_path) unless name raise "Expected key 'CFBundleExecutable' in '#{info_plist_path}'" end name end |
#info_plist_path ⇒ Object
Returns the Info.plist path.
104 105 106 |
# File 'lib/run_loop/app.rb', line 104 def info_plist_path @info_plist_path ||= File.join(path, 'Info.plist') end |
#marketing_version ⇒ RunLoop::Version? Also known as: short_bundle_version
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.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/run_loop/app.rb', line 201 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 |
#physical_device? ⇒ Boolean
True if the app has been built for physical devices
143 144 145 146 147 |
# File 'lib/run_loop/app.rb', line 143 def physical_device? arches.any? do |arch| arch[/arm/, 0] end end |
#sha1 ⇒ Object
Returns the sha1 of the application.
265 266 267 |
# File 'lib/run_loop/app.rb', line 265 def sha1 RunLoop::Directory.directory_digest(path) end |
#simulator? ⇒ Boolean
True if the app has been built for the simulator
138 139 140 |
# File 'lib/run_loop/app.rb', line 138 def simulator? arches.include?("i386") || arches.include?("x86_64") end |
#valid? ⇒ Boolean
Is this a valid app?
73 74 75 |
# File 'lib/run_loop/app.rb', line 73 def valid? App.valid?(path) end |