Class: Snapshot::Simulators

Inherits:
Object
  • Object
show all
Defined in:
lib/snapshot/simulators.rb

Class Method Summary collapse

Class Method Details

.available_devices(name_only = false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/snapshot/simulators.rb', line 17

def self.available_devices(name_only = false)
  Helper.log.info "Fetching available devices" if $verbose
  result = []
  
  output = self.raw_simulators

  output.split("\n").each do |current|
    # Example: "iPhone 5 (8.1 Simulator) [C49ECC4A-5A3D-44B6-B9BF-4E25BC326400]"
    # Example: "iPhone 6 (9.0) [072E4EA2-861F-44CD-AB77-FB1FE07E541C]"
    
    match = current.match /((.+?) \(.+?\)) \[.+?\]/
    next if match.nil?
    
    if name_only
      result << match[2]
    else
      result << match[1]
    end
  end

  return result
end

.raw_simulatorsObject

we do it using ‘open3` since only ` just randomly hangs with instruments -s

Returns:

  • the raw value of the ‘instruments -s` command



7
8
9
10
11
12
13
14
15
# File 'lib/snapshot/simulators.rb', line 7

def self.raw_simulators
  return @result if @result

  Open3.popen3('instruments -s') do |stdin, stdout, stderr, wait_thr|
    @result = stdout.read
  end
  
  @result || ''
end