Class: RunLoop::Device
- Inherits:
-
Object
- Object
- RunLoop::Device
- Defined in:
- lib/run_loop/device.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#simulator_accessibility_plist_path ⇒ Object
readonly
Returns the value of attribute simulator_accessibility_plist_path.
-
#simulator_log_file_path ⇒ Object
readonly
Returns the value of attribute simulator_log_file_path.
-
#simulator_preferences_plist_path ⇒ Object
readonly
Returns the value of attribute simulator_preferences_plist_path.
-
#simulator_root_dir ⇒ Object
readonly
Returns the value of attribute simulator_root_dir.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#udid ⇒ Object
readonly
Returns the value of attribute udid.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.device_with_identifier(udid_or_name, sim_control = RunLoop::SimControl.new) ⇒ RunLoop::Device
Returns a device given a udid or name.
Instance Method Summary collapse
-
#initialize(name, version, udid, state = nil) ⇒ Device
constructor
Create a new device.
-
#instruction_set ⇒ String
Return the instruction set for this device.
-
#instruments_identifier(xcode_tools = RunLoop::XCTools.new) ⇒ String
Returns and instruments-ready device identifier that is a suitable value for DEVICE_TARGET environment variable.
-
#physical_device? ⇒ Boolean
Is this a physical device?.
-
#simulator? ⇒ Boolean
Is this a simulator?.
- #to_s ⇒ Object
Constructor Details
#initialize(name, version, udid, state = nil) ⇒ Device
Create a new device.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/run_loop/device.rb', line 24 def initialize(name, version, udid, state=nil) @name = name @udid = udid @state = state if version.is_a? String @version = RunLoop::Version.new version else @version = version end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/run_loop/device.rb', line 4 def name @name end |
#simulator_accessibility_plist_path ⇒ Object (readonly)
Returns the value of attribute simulator_accessibility_plist_path.
9 10 11 |
# File 'lib/run_loop/device.rb', line 9 def simulator_accessibility_plist_path @simulator_accessibility_plist_path end |
#simulator_log_file_path ⇒ Object (readonly)
Returns the value of attribute simulator_log_file_path.
11 12 13 |
# File 'lib/run_loop/device.rb', line 11 def simulator_log_file_path @simulator_log_file_path end |
#simulator_preferences_plist_path ⇒ Object (readonly)
Returns the value of attribute simulator_preferences_plist_path.
10 11 12 |
# File 'lib/run_loop/device.rb', line 10 def simulator_preferences_plist_path @simulator_preferences_plist_path end |
#simulator_root_dir ⇒ Object (readonly)
Returns the value of attribute simulator_root_dir.
8 9 10 |
# File 'lib/run_loop/device.rb', line 8 def simulator_root_dir @simulator_root_dir end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
7 8 9 |
# File 'lib/run_loop/device.rb', line 7 def state @state end |
#udid ⇒ Object (readonly)
Returns the value of attribute udid.
6 7 8 |
# File 'lib/run_loop/device.rb', line 6 def udid @udid end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
5 6 7 |
# File 'lib/run_loop/device.rb', line 5 def version @version end |
Class Method Details
.device_with_identifier(udid_or_name, sim_control = RunLoop::SimControl.new) ⇒ RunLoop::Device
Returns a device given a udid or name. In the case of a physical device, the udid is the device identifier. In the case of a simulator the name is the _instruments identifier_ as reported by ‘$ xcrun instruments -s devices` - this is the identifier that can be passed to instruments.
Note that if you have a device and simulator with the same name, the simulator will always be selected.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/run_loop/device.rb', line 58 def self.device_with_identifier(udid_or_name, sim_control=RunLoop::SimControl.new) simulator = sim_control.simulators.detect do |sim| sim.instruments_identifier == udid_or_name || sim.udid == udid_or_name end return simulator if !simulator.nil? physical_device = sim_control.xctools.instruments(:devices).detect do |device| device.name == udid_or_name || device.udid == udid_or_name end return physical_device if !physical_device.nil? raise ArgumentError, "Could not find a device with a UDID or name matching '#{udid_or_name}'" end |
Instance Method Details
#instruction_set ⇒ String
Finding the instruction set of a device requires a third-party tool like ideviceinfo. Example: ‘$ ideviceinfo -u 89b59 < snip > ab7ba –key ’CPUArchitecture’ => arm64`
Return the instruction set for this device.
Simulator The simulator instruction set will be i386 or x86_64 depending on the the (marketing) name of the device.
130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/run_loop/device.rb', line 130 def instruction_set if self.simulator? if ['iPhone 4s', 'iPhone 5', 'iPad 2', 'iPad Retina'].include?(self.name) 'i386' else 'x86_64' end else raise 'Finding the instruction set of a device requires a third-party tool like ideviceinfo' end end |
#instruments_identifier(xcode_tools = RunLoop::XCTools.new) ⇒ String
Returns and instruments-ready device identifier that is a suitable value for DEVICE_TARGET environment variable.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/run_loop/device.rb', line 90 def instruments_identifier(xcode_tools=RunLoop::XCTools.new) if physical_device? self.udid else unless xcode_tools.xcode_version_gte_6? raise "Expected Xcode >= 6, but found version #{xcode_tools.xcode_version} - cannot create an identifier" end if self.version == RunLoop::Version.new('7.0.3') version_part = self.version.to_s else version_part = "#{self.version.major}.#{self.version.minor}" end "#{self.name} (#{version_part} Simulator)" end end |
#physical_device? ⇒ Boolean
Is this a physical device?
108 109 110 |
# File 'lib/run_loop/device.rb', line 108 def physical_device? not self.udid[/[a-f0-9]{40}/, 0].nil? end |
#simulator? ⇒ Boolean
Is this a simulator?
114 115 116 |
# File 'lib/run_loop/device.rb', line 114 def simulator? not self.physical_device? end |
#to_s ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/run_loop/device.rb', line 76 def to_s if simulator? "#<Simulator: #{instruments_identifier} #{udid} #{instruction_set}>" else "#<Device: #{name} #{udid}>" end end |