Class: Luffa::IDeviceInstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/luffa/ios/ideviceinstaller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ipa, bundle_id) ⇒ IDeviceInstaller

Returns a new instance of IDeviceInstaller.



9
10
11
12
# File 'lib/luffa/ios/ideviceinstaller.rb', line 9

def initialize(ipa, bundle_id)
  @ipa = ipa
  @bundle_id = bundle_id
end

Instance Attribute Details

#bundle_idObject (readonly)

Returns the value of attribute bundle_id.



7
8
9
# File 'lib/luffa/ios/ideviceinstaller.rb', line 7

def bundle_id
  @bundle_id
end

#ipaObject (readonly)

Returns the value of attribute ipa.



6
7
8
# File 'lib/luffa/ios/ideviceinstaller.rb', line 6

def ipa
  @ipa
end

Instance Method Details

#bin_pathObject



14
15
16
# File 'lib/luffa/ios/ideviceinstaller.rb', line 14

def bin_path
  @bin_path ||= `which ideviceinstaller`.chomp!
end

#bundle_installed?(udid) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/luffa/ios/ideviceinstaller.rb', line 43

def bundle_installed?(udid)
  cmd = "#{bin_path} --udid #{udid} --list-apps"
  Luffa.log_unix_cmd(cmd) if Luffa::Environment.debug?

  Open3.popen3(cmd) do  |_, stdout,  stderr, _|
    err = stderr.read.strip
    Luffa.log_fail(err) if err && err != ''

    out = stdout.read.strip
    out.strip.split(/\s/).include? bundle_id
  end
end

#idevice_id_available?Boolean

Returns:

  • (Boolean)


94
95
96
97
# File 'lib/luffa/ios/ideviceinstaller.rb', line 94

def idevice_id_available?
  path = idevice_id_bin_path
  path and File.exist? path
end

#idevice_id_bin_pathObject



90
91
92
# File 'lib/luffa/ios/ideviceinstaller.rb', line 90

def idevice_id_bin_path
  @idevice_id_bin_path ||= `which idevice_id`.chomp!
end

#ideviceinstaller_available?Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/luffa/ios/ideviceinstaller.rb', line 18

def ideviceinstaller_available?
  path = bin_path
  path and File.exist? bin_path
end

#install(udid, cmd) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/luffa/ios/ideviceinstaller.rb', line 23

def install(udid, cmd)
  case cmd
    when :install_internal
      ipa
      Retriable.retriable do
        uninstall udid
      end
      Retriable.retriable do
        install_internal udid
      end
    when :uninstall
      Retriable.retriable do
        uninstall udid
      end
    else
      cmds = [:install_internal, :uninstall]
      raise ArgumentError, "expected '#{cmd}' to be one of '#{cmds}'"
  end
end

#install_internal(udid) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/luffa/ios/ideviceinstaller.rb', line 56

def install_internal(udid)
  return true if bundle_installed? udid

  cmd = "#{bin_path} --udid #{udid} --install #{ipa}"
  Luffa.log_unix_cmd(cmd) if Luffa::Environment.debug?

  Open3.popen3(cmd) do  |_, _,  stderr, _|
    err = stderr.read.strip
    Luffa.log_fail(err) if err && err != ''
  end

  unless bundle_installed? udid
    raise "could not install '#{ipa}' on '#{udid}' with '#{bundle_id}'"
  end
  true
end

#physical_devices_for_testing(xcode_tools) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/luffa/ios/ideviceinstaller.rb', line 99

def physical_devices_for_testing(xcode_tools)
  # Xcode 6 + iOS 8 - devices on the same network, whether development or
  # not, appear when calling $ xcrun instruments -s devices. For the
  # purposes of testing, we will only try to connect to devices that are
  # connected via USB.
  @physical_devices_for_testing ||= lambda {
    devices = xcode_tools.instruments(:devices)
    if idevice_id_available?
      white_list = `#{idevice_id_bin_path} -l`.strip.split("\n")
      devices.select { | device | white_list.include?(device.udid) }
    else
      devices
    end
  }.call
end

#uninstall(udid) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/luffa/ios/ideviceinstaller.rb', line 73

def uninstall(udid)
  return true unless bundle_installed? udid

  cmd = "#{bin_path} -udid #{udid} --uninstall #{bundle_id}"
  Luffa.log_unix_cmd(cmd) if Luffa::Environment.debug?

  Open3.popen3(cmd) do  |_, _,  stderr, _|
    err = stderr.read.strip
    Luffa.log_fail(err) if err && err != ''
  end

  if bundle_installed? udid
    raise "could not uninstall '#{bundle_id}' on '#{udid}'"
  end
  true
end