Class: RunLoop::App

Inherits:
Object
  • Object
show all
Defined in:
lib/run_loop/app.rb

Overview

A class for interacting with .app bundles.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_bundle_path) ⇒ RunLoop::App

Note:

The ‘app_bundle_path` is expanded during initialization.

Creates a new App instance.

Parameters:

  • app_bundle_path (String)

    A path to a .app



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/run_loop/app.rb', line 15

def initialize(app_bundle_path)
  @path = File.expand_path(app_bundle_path)

  if !App.valid?(app_bundle_path)
    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

Instance Attribute Details

#pathString (readonly)

Returns The path to the app bundle .app.

Returns:

  • (String)

    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

#archesObject

Returns the arches for the binary.



92
93
94
# File 'lib/run_loop/app.rb', line 92

def arches
  @arches ||= lipo.info
end

#bundle_identifierString

Inspects the app’s Info.plist for the bundle identifier.

Returns:

  • (String)

    The value of CFBundleIdentifier.

Raises:

  • (RuntimeError)

    If the plist cannot be read or the CFBundleIdentifier is empty or does not exist.



71
72
73
74
75
76
77
# File 'lib/run_loop/app.rb', line 71

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_versionObject

Inspects the app’s file for the server version



109
110
111
112
113
114
115
116
# File 'lib/run_loop/app.rb', line 109

def calabash_server_version
  version = nil
  executables.each do |executable|
    version = strings(executable).server_version
    break if version
  end
  version
end

#executable_nameString

Inspects the app’s Info.plist for the executable name.

Returns:

  • (String)

    The value of CFBundleExecutable.

Raises:

  • (RuntimeError)

    If the plist cannot be read or the CFBundleExecutable is empty or does not exist.



83
84
85
86
87
88
89
# File 'lib/run_loop/app.rb', line 83

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_pathObject

Returns the Info.plist path.

Raises:

  • (RuntimeError)

    If there is no Info.plist.



63
64
65
# File 'lib/run_loop/app.rb', line 63

def info_plist_path
  @info_plist_path ||= File.join(path, 'Info.plist')
end

#physical_device?Boolean

True if the app has been built for physical devices

Returns:

  • (Boolean)


102
103
104
105
106
# File 'lib/run_loop/app.rb', line 102

def physical_device?
  arches.any? do |arch|
    arch[/arm/, 0]
  end
end

#sha1Object

Returns the sha1 of the application.



147
148
149
# File 'lib/run_loop/app.rb', line 147

def sha1
  RunLoop::Directory.directory_digest(path)
end

#simulator?Boolean

True if the app has been built for the simulator

Returns:

  • (Boolean)


97
98
99
# File 'lib/run_loop/app.rb', line 97

def simulator?
  arches.include?("i386") || arches.include?("x86_64")
end

#valid?Boolean

Is this a valid app?

Returns:

  • (Boolean)


45
46
47
# File 'lib/run_loop/app.rb', line 45

def valid?
  App.valid?(path)
end