Class: RunLoop::Ipa

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

Overview

A model of the an .ipa - a application binary for iOS devices.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path_to_ipa) ⇒ Calabash::Ipa

Create a new ipa instance.

Parameters:

  • path_to_ipa (String)

    The path the .ipa file.

Raises:

  • (RuntimeError)

    If the file does not exist.

  • (RuntimeError)

    If the file does not end in .ipa.



22
23
24
25
26
27
28
29
30
31
# File 'lib/run_loop/ipa.rb', line 22

def initialize(path_to_ipa)
  unless File.exist? path_to_ipa
    raise "Expected an ipa at '#{path_to_ipa}'"
  end

  unless path_to_ipa.end_with?('.ipa')
    raise "Expected '#{path_to_ipa}' to be an .ipa"
  end
  @path = path_to_ipa
end

Instance Attribute Details

#bundle_identifierString (readonly)

The bundle identifier of this ipa.

Returns:

  • (String)

    A string representation of this ipa’s CFBundleIdentifier

Raises:

  • (RuntimeError)

    If ipa does not expand into a Payload/<app name>.app directory.

  • (RuntimeError)

    If an Info.plist does exist in the .app.



15
16
17
# File 'lib/run_loop/ipa.rb', line 15

def bundle_identifier
  @bundle_identifier
end

#pathString (readonly)

The path to this .ipa.

Returns:

  • (String)

    A path to this .ipa.



9
10
11
# File 'lib/run_loop/ipa.rb', line 9

def path
  @path
end

Instance Method Details

#calabash_server_versionObject

Inspects the app’s file for the server version



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/run_loop/ipa.rb', line 91

def calabash_server_version
  if bundle_dir.nil? || !File.exist?(bundle_dir)
    raise "Expected a '#{File.basename(path).split('.').first}.app'\nat path '#{payload_dir}'"
  else
    if !executable_name.nil? && executable_name != ''
      path_to_bin = File.join(bundle_dir, executable_name)
      xcrun ||= RunLoop::Xcrun.new
      hash = xcrun.exec(["strings", path_to_bin])
      unless hash.nil?
        version_str = hash[:out][/CALABASH VERSION: \d+\.\d+\.\d+/, 0]
        unless version_str.nil? || version_str == ""
          server_ver = version_str.split(":")[1].delete(' ')
          RunLoop::Version.new(server_ver)
        end
      end
    end
  end
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.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/run_loop/ipa.rb', line 71

def executable_name
  if bundle_dir.nil? || !File.exist?(bundle_dir)
    raise "Expected a '#{File.basename(path).split('.').first}.app'\nat path '#{payload_dir}'"
  end

  @executable_name ||= lambda {
    info_plist_path = File.join(bundle_dir, 'Info.plist')
    unless File.exist? info_plist_path
      raise "Expected an 'Info.plist' at '#{bundle_dir}'"
    end
    name = plist_buddy.plist_read('CFBundleExecutable', info_plist_path)

    unless name
      raise "Expected key 'CFBundleExecutable' in '#{info_plist_path}'"
    end
    name
  }.call
end