Class: ParallelCalabash::IosHelper
- Inherits:
-
Object
- Object
- ParallelCalabash::IosHelper
show all
- Includes:
- DevicesHelper
- Defined in:
- lib/parallel_calabash/adb_helper.rb
Instance Method Summary
collapse
#device_for_process, #number_of_connected_devices
Constructor Details
#initialize(filter = nil, default_simulator = nil, config_file = nil, instruments = nil) ⇒ IosHelper
Returns a new instance of IosHelper.
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/parallel_calabash/adb_helper.rb', line 52
def initialize(filter = nil, default_simulator = nil, config_file = nil, instruments = nil)
@filter = filter || []
@default_simulator = default_simulator || {}
config_file = config_file || "#{ENV['HOME']}/.parallel_calabash"
if config_file.is_a? Hash
@config = config_file
else
@config = File.exist?(config_file) ? eval(File.read(config_file)) : {}
end
@instruments = instruments || %x(instruments -s devices ; echo)
end
|
Instance Method Details
#apply_filter(configs) ⇒ Object
113
114
115
116
117
118
119
|
# File 'lib/parallel_calabash/adb_helper.rb', line 113
def apply_filter(configs)
return configs if @filter.empty?
filter_join = @filter.join('|')
configs.select do |c|
[c.keys, c.values].flatten.find { |k| k.to_s.match(filter_join) }
end
end
|
#compute_devices ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/parallel_calabash/adb_helper.rb', line 95
def compute_devices
users = @config[:USERS] || []
init = @config[:INIT] || ''
devices = remove_unconnected_devices(@config[:DEVICES])
fail 'Devices configured, but no devices attached!' if devices.empty?
configs = devices.map.with_index do |d, i|
if users[i]
d[:USER] = users[i]
d[:INIT] = init
d
else
print "** No user for device #{d}"
nil
end
end
configs.compact
end
|
#compute_simulators ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/parallel_calabash/adb_helper.rb', line 80
def compute_simulators
port = (@config[:CALABASH_SERVER_PORT] || 28000).to_i
users = @config[:USERS] || []
init = @config[:INIT] || ''
simulator = @config[:DEVICE_TARGET] || nil
users.map.with_index do |u, i|
{}.tap do |my_hash|
my_hash[:USER] = u
my_hash[:CALABASH_SERVER_PORT] = port + i
my_hash[:INIT] = init
my_hash[:DEVICE_TARGET] = simulator unless simulator.nil?
end
end
end
|
#connected_devices_with_model_info ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/parallel_calabash/adb_helper.rb', line 68
def connected_devices_with_model_info
return @devices if @devices
if @config[:DEVICES]
configs = apply_filter(compute_devices)
fail '** No devices (or users) unfiltered!' if configs.empty?
else
configs = apply_filter(compute_simulators)
configs = configs.empty? ? [@default_simulator] : configs
end
@devices = configs
end
|
#remove_unconnected_devices(configs) ⇒ Object
121
122
123
124
125
126
127
|
# File 'lib/parallel_calabash/adb_helper.rb', line 121
def remove_unconnected_devices(configs)
udids = @instruments.each_line.map { |n| n.match(/\[(.*)\]/) && $1 }.flatten.compact
configs.find_all do |c|
var = c[:DEVICE_TARGET]
!udids.grep(var).empty?
end
end
|
#xcode7? ⇒ Boolean
64
65
66
|
# File 'lib/parallel_calabash/adb_helper.rb', line 64
def xcode7?
!@instruments.match(' Simulator\)')
end
|