fourflusher 1.0.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a35973aab1aa95c3d8aafd5faa10aea43d14891d
4
- data.tar.gz: 297b32aca985dca711baabb12d243396fcdb13e4
3
+ metadata.gz: 51d11f36e15ae2cef0aec386296a4ff9888ece0e
4
+ data.tar.gz: a363748b2fd402115f6ca433f802f22160ead987
5
5
  SHA512:
6
- metadata.gz: 8cedb38cb098754a409cc3cfd37d117cb464c63eabb3f397f98a586d2c272668dd9e9f8b262307c61cae044e32b3c7a0bf0a5c3a13a0c15f29bf3df86a66c4a6
7
- data.tar.gz: 0bdca3894776bb5b01518beb78a9f33a7b671390a4a94f811126864b1a8e4e583a0cde49fd34d21fdf8d35cd79dca089a78a1c08080737d8935f521766dc218d
6
+ metadata.gz: eea706a0d6b0bb7bb538557a729b398714e4b45c354168ff2544f3e5fd0d8aad46b33bd6e21812bedb3838b9c6261b370c844baa5cc0a35c23e836d3f4773d12
7
+ data.tar.gz: e327d66420dcf7c0178bcf7a52ad8cdda85ae06599980b78c3be2e8a4eee97f5c414cb4492efb89753d43ea8f0e7701f3213697b61775c1292455a2b4bb42193
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
@@ -1,9 +1,12 @@
1
1
  language: ruby
2
2
  os: osx
3
- osx_image: xcode7.2
4
- rvm: 2.0.0-p598
3
+ osx_image: xcode8
4
+ rvm: 2.0.0-p648
5
5
  cache: bundler
6
6
  before_install: gem install bundler
7
+ before_script:
8
+ # Useful for reference while reviewing travis failures
9
+ - xcrun simctl list -j devices
7
10
  script:
8
11
  - bundle exec rake spec
9
12
  - bundle exec rake rubocop
@@ -0,0 +1,89 @@
1
+
2
+ ## 2.0.0 (2016-10-02)
3
+
4
+ ##### Enhancements
5
+
6
+ * None
7
+
8
+ ##### Bug Fixes
9
+
10
+ * None
11
+
12
+ ## v2.0.0 (2016-10-02)
13
+
14
+ ##### Breaking
15
+
16
+ * Use JSON output from `xcrun simctl list`. Drop support for Xcode 6 (doesn't support JSON output)
17
+ [Ben Asher](https://github.com/benasher44)
18
+ [#6](https://github.com/CocoaPods/fourflusher/pull/6)
19
+
20
+ ##### Enhancements
21
+
22
+ * Update simulator count for Travis
23
+ [Boris Bügling](https://github.com/neonichu)
24
+ [#5](https://github.com/CocoaPods/fourflusher/pull/5)
25
+
26
+ * A more helpful error message for missing simulators
27
+ [Radek Pietruszewski](https://github.com/radex)
28
+ [#4](https://github.com/CocoaPods/fourflusher/pull/4)
29
+
30
+ ##### Bug Fixes
31
+
32
+ * None
33
+
34
+ ## v1.0.1 (2016-06-25)
35
+
36
+ ##### Enhancements
37
+
38
+ * Show better error for `:oldest` simulator search
39
+ [Boris Bügling](https://github.com/neonichu)
40
+
41
+ ## v1.0.0 (2016-06-24)
42
+
43
+ ##### Enhancements
44
+
45
+ * Improve finding simulators
46
+ [Boris Bügling](https://github.com/neonichu)
47
+
48
+ ## v0.3.2 (2016-06-16)
49
+
50
+ ##### Enhancements
51
+
52
+ * Support for parsing iOS 10.0 and tvOS 10.0
53
+ [Boris Bügling](https://github.com/neonichu)
54
+
55
+ ##### Bug Fixes
56
+
57
+ * Rubocop fixes
58
+ [Boris Bügling](https://github.com/neonichu)
59
+
60
+ ## v0.3.1 (2016-05-30)
61
+
62
+ ##### Enhancements
63
+
64
+ * Travis CI improvements
65
+ [Boris Bügling](https://github.com/neonichu)
66
+ [#1](https://github.com/CocoaPods/fourflusher/pull/1)
67
+
68
+ * Handle missing Xcode more gracefully
69
+ [Boris Bügling](https://github.com/neonichu)
70
+
71
+ ## v0.3.0 (2015-12-29)
72
+
73
+ ##### Enhancements
74
+
75
+ * Allow specifying constraints for `destination()`
76
+ [Boris Bügling](https://github.com/neonichu)
77
+
78
+ ## v0.2.0 (2015-12-29)
79
+
80
+ ##### Enhancements
81
+
82
+ * Allow constraining simulators by OS version
83
+ [Boris Bügling](https://github.com/neonichu)
84
+
85
+ ## v0.1.0 (2015-12-18)
86
+
87
+ * List usable simulators. Find simulators by name. Get the destination setting for the simulator to pass to Xcodebuild
88
+ [Boris Bügling](https://github.com/neonichu)
89
+
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fourflusher (2.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.3.0)
10
+ astrolabe (1.3.1)
11
+ parser (~> 2.2)
12
+ diff-lcs (1.2.5)
13
+ parser (2.3.1.4)
14
+ ast (~> 2.2)
15
+ powerpack (0.1.1)
16
+ rainbow (2.1.0)
17
+ rake (10.5.0)
18
+ rspec (2.99.0)
19
+ rspec-core (~> 2.99.0)
20
+ rspec-expectations (~> 2.99.0)
21
+ rspec-mocks (~> 2.99.0)
22
+ rspec-core (2.99.2)
23
+ rspec-expectations (2.99.2)
24
+ diff-lcs (>= 1.1.3, < 2.0)
25
+ rspec-mocks (2.99.4)
26
+ rubocop (0.35.1)
27
+ astrolabe (~> 1.3)
28
+ parser (>= 2.2.3.0, < 3.0)
29
+ powerpack (~> 0.1)
30
+ rainbow (>= 1.99.1, < 3.0)
31
+ ruby-progressbar (~> 1.7)
32
+ tins (<= 1.6.0)
33
+ ruby-progressbar (1.8.1)
34
+ tins (1.6.0)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ bundler (~> 1.11)
41
+ fourflusher!
42
+ rake (~> 10.0)
43
+ rspec (~> 2)
44
+ rubocop (~> 0.35.0)
45
+
46
+ BUNDLED WITH
47
+ 1.13.1
@@ -1,4 +1,5 @@
1
1
  require 'fourflusher/simctl'
2
+ require 'json'
2
3
  require 'rubygems/version'
3
4
 
4
5
  module Fourflusher
@@ -8,12 +9,6 @@ module Fourflusher
8
9
  attr_reader :name
9
10
  attr_reader :os_version
10
11
 
11
- def self.match(line, os_name, os_version)
12
- sims = []
13
- @@sim_regex.match(line) { |m| sims << Simulator.new(m, os_name, Gem::Version.new(os_version)) }
14
- sims
15
- end
16
-
17
12
  def os_name
18
13
  @os_name.downcase.to_sym
19
14
  end
@@ -26,73 +21,115 @@ module Fourflusher
26
21
  "#{@name} (#{@id}) - #{@os_name} #{@os_version}"
27
22
  end
28
23
 
29
- private
24
+ # Compare function for sorting simulators in order by
25
+ # - OS Name: ascending
26
+ # - OS Version: descending
27
+ # - Device type: iPhone first, then ascending
28
+ # - Model: ascending
29
+ def sim_list_compare(other)
30
+ return os_name.to_s <=> other.os_name.to_s unless os_name == other.os_name
31
+ return other.os_version <=> os_version unless os_version == other.os_version
32
+ device1, model1 = device_and_model
33
+ device2, model2 = other.device_and_model
34
+ unless device1 == device2
35
+ return -1 if device1 == 'iPhone'
36
+ return 1 if device2 == 'iPhone'
37
+ return device1 <=> device2
38
+ end
39
+ model1 <=> model2
40
+ end
41
+
42
+ # Returns the [device, model] for use during sorting
43
+ # Examples: [iPhone, 5s], [iPhone, 6s Plus], [Apple Watch Series 2, 38mm]
44
+ def device_and_model
45
+ if os_name == :watchos
46
+ # Sample string: Apple Watch Series 2 - 38mm
47
+ name.split ' - '
48
+ else
49
+ # Sample string: "iPhone 5s" or "iPhone 6 Plus" or "iPad Air 2"
50
+ if name.start_with? 'Apple TV'
51
+ # The last part is the model, and the rest is the device
52
+ parts = name.rpartition(' ').reject { |str| str.strip.empty? }
53
+ [parts[0...-1].join(' '), parts.drop(parts.count - 1).join(' ')].map(&:strip)
54
+ else
55
+ # The first part is device, and the rest is the model
56
+ name.split ' ', 2
57
+ end
58
+ end
59
+ end
30
60
 
31
- @@sim_regex = /^\s*(?<sim_name>[^\)]*?) \((?<sim_id>[^\)]*?)\) \((?<sim_state>[^\)]*?)\)$/
61
+ private
32
62
 
33
- def initialize(match_data, os_name, os_version)
34
- @id = match_data['sim_id']
35
- @name = match_data['sim_name']
63
+ def initialize(device_json, os_name, os_version)
64
+ @id = device_json['udid']
65
+ @name = device_json['name']
36
66
  @os_name = os_name
37
- @os_version = os_version
67
+ @os_version = Gem::Version.new os_version
38
68
  end
39
69
  end
40
70
 
41
- # -- iOS 9.2 --
42
- # iPhone 4s (C0404A23-2D2D-4208-8CEC-774194D06759) (Shutdown)
43
- # iPhone 5 (7A0F62DD-8330-44F0-9828-AC8B1BC9BF05) (Shutdown)
44
- # iPhone 5s (51C1CB50-FBCB-47ED-B8FF-68C816BF0932) (Shutdown)
45
- # iPhone 6 (6F4E143A-6914-476E-90BF-51B680B8E2EF) (Shutdown)
46
- # iPhone 6 Plus (BEB9BFE9-AF1A-4FEA-9FA5-CAFD5243CA42) (Shutdown)
47
- # iPhone 6s (98DB904B-DF98-4F3C-AB21-A4D133604BA4) (Shutdown)
48
- # iPhone 6s Plus (65838307-4C03-4DD3-84E4-A6477CFD3490) (Shutdown)
49
- # iPad 2 (349C1313-6C9C-48C6-8849-DAB18BE2F15C) (Shutdown)
50
- # iPad Retina (30909168-4C90-48CD-B142-86DCF7B1372A) (Shutdown)
51
- # iPad Air (A8B5F651-C215-459C-95C6-663194F2277B) (Shutdown)
52
- # iPad Air 2 (BFDB363E-D514-490C-A1D6-AC86402089BA) (Shutdown)
53
- # iPad Pro (AE5DA548-66F6-4FCE-AA6D-5E6E17CD721E) (Shutdown)
54
- # -- tvOS 9.1 --
55
- # Apple TV 1080p (C5A44868-685C-4D72-BEBD-102246C870F7) (Shutdown)
56
- # -- watchOS 2.1 --
57
- # Apple Watch - 38mm (FE557B65-A044-44C3-96AC-2EAC395A6090) (Shutdown)
58
- # Apple Watch - 42mm (C9138FAE-6812-4BB5-A463-76520C116AF4) (Shutdown)
71
+ # {
72
+ # "devices" : {
73
+ # "iOS 10.0" : [
74
+ # {
75
+ # "state" : "Shutdown",
76
+ # "availability" : "(available)",
77
+ # "name" : "iPhone 5",
78
+ # "udid" : "B7D21008-CC16-47D6-A9A9-885FE1FC47A8"
79
+ # },
80
+ # {
81
+ # "state" : "Shutdown",
82
+ # "availability" : "(available)",
83
+ # "name" : "iPhone 5s",
84
+ # "udid" : "38EAE7BD-90C3-4C3D-A672-3AF683EEC5A2"
85
+ # },
86
+ # ]
87
+ # }
88
+ # }
59
89
 
60
90
  # Executes `simctl` commands
61
91
  class SimControl
62
- def initialize
63
- @os_regex = /^-- (?<os_name>.*?) (?<os_version>[0-9][0-9]?\.[0-9]) --$/
64
- end
65
-
66
92
  def simulator(filter, os_name = :ios, minimum_version = '1.0')
67
93
  usable_simulators(filter, os_name, minimum_version).first
68
94
  end
69
95
 
70
96
  def usable_simulators(filter = nil, os = :ios, minimum_version = '1.0')
71
- os_name = ''
72
- os_version = ''
73
- sims = []
74
-
75
- list(['devices']).lines.each do |line|
76
- @os_regex.match(line) do |m|
77
- os_name = m['os_name']
78
- os_version = m['os_version']
79
- end
80
- sims += Simulator.match(line, os_name, os_version)
81
- end
82
-
97
+ sims = fetch_sims
83
98
  oses = sims.map(&:os_name).uniq
84
99
  os = os.downcase.to_sym
85
- fail "Invalid OS `#{os}`, valid values are #{oses.join(', ')}" unless oses.include?(os)
100
+
101
+ unless oses.include?(os)
102
+ fail "Could not find a `#{os}` simulator (valid values: #{oses.join(', ')}). Ensure that "\
103
+ "Xcode -> Window -> Devices has at least one `#{os}` simulator listed or otherwise add one."
104
+ end
86
105
 
87
106
  return sims if filter.nil?
88
107
  minimum_version = Gem::Version.new(minimum_version)
89
108
  sims = sims.select { |sim| sim.os_name == os && sim.compatible?(minimum_version) }
90
109
 
91
- return [sims.first] if filter == :oldest
110
+ return [sims.min_by(&:os_version)] if filter == :oldest
92
111
 
93
112
  found_sims = sims.select { |sim| sim.name == filter }
94
113
  return found_sims if found_sims.count > 0
95
114
  sims.select { |sim| sim.name.start_with?(filter) }
96
115
  end
116
+
117
+ private
118
+
119
+ # Gets the simulators and transforms the simctl json into Simulator objects
120
+ def fetch_sims
121
+ device_list = JSON.parse(list(['-j', 'devices']))['devices']
122
+ unless device_list.is_a?(Hash)
123
+ msg = "Expected devices to be of type Hash but instated found #{device_list.class}"
124
+ fail Fourflusher::Informative, msg
125
+ end
126
+ device_list.flat_map do |runtime_str, devices|
127
+ # Sample string: iOS 9.3
128
+ os_name, os_version = runtime_str.split ' '
129
+ devices.map do |device|
130
+ Simulator.new(device, os_name, os_version) if device['availability'] == '(available)'
131
+ end
132
+ end.compact.sort(&:sim_list_compare)
133
+ end
97
134
  end
98
135
  end
@@ -1,3 +1,3 @@
1
1
  module Fourflusher
2
- VERSION = '1.0.1'
2
+ VERSION = '2.0.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fourflusher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris Bügling
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-25 00:00:00.000000000 Z
11
+ date: 2016-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -76,7 +76,9 @@ files:
76
76
  - .gitignore
77
77
  - .rubocop.yml
78
78
  - .travis.yml
79
+ - CHANGELOG.md
79
80
  - Gemfile
81
+ - Gemfile.lock
80
82
  - LICENSE.txt
81
83
  - README.md
82
84
  - Rakefile
@@ -115,4 +117,3 @@ signing_key:
115
117
  specification_version: 4
116
118
  summary: A library for interacting with Xcode simulators.
117
119
  test_files: []
118
- has_rdoc: