Class: Device
- Inherits:
-
Object
- Object
- Device
- Defined in:
- lib/peach/device.rb
Instance Attribute Summary collapse
-
#device_type ⇒ Object
readonly
Returns the value of attribute device_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#runtime ⇒ Object
readonly
Returns the value of attribute runtime.
-
#udid ⇒ Object
readonly
Returns the value of attribute udid.
Class Method Summary collapse
- .current_devices(xc:) ⇒ Object
-
.destroy_all(xc:) ⇒ Object
class functions.
- .device_type(udid:, xc:) ⇒ Object
- .device_type_identifier(udid:, xc:) ⇒ Object
- .load_devices ⇒ Object
Instance Method Summary collapse
- #==(o) ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #eql? ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(name:, device_type:, runtime:, udid: nil) ⇒ Device
constructor
A new instance of Device.
Constructor Details
#initialize(name:, device_type:, runtime:, udid: nil) ⇒ Device
Returns a new instance of Device.
6 7 8 9 10 11 |
# File 'lib/peach/device.rb', line 6 def initialize(name:, device_type:, runtime:, udid: nil) @name = name @device_type = device_type @runtime = runtime @udid = udid end |
Instance Attribute Details
#device_type ⇒ Object (readonly)
Returns the value of attribute device_type.
4 5 6 |
# File 'lib/peach/device.rb', line 4 def device_type @device_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/peach/device.rb', line 4 def name @name end |
#runtime ⇒ Object (readonly)
Returns the value of attribute runtime.
4 5 6 |
# File 'lib/peach/device.rb', line 4 def runtime @runtime end |
#udid ⇒ Object (readonly)
Returns the value of attribute udid.
4 5 6 |
# File 'lib/peach/device.rb', line 4 def udid @udid end |
Class Method Details
.current_devices(xc:) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/peach/device.rb', line 48 def self.current_devices(xc:) devices = Array.new simctl_json = JSON.parse(load_devices) device_list = simctl_json['devices'] device_list.each do |type, ds| runtime = xc.runtime_name(type) ds.each do |d| device_name = d["name"] device_udid = d["udid"] device_type = device_type(udid: device_udid, xc: xc) devices << Device.new(name: device_name, device_type: device_type, runtime: runtime, udid: device_udid) end end devices end |
.destroy_all(xc:) ⇒ Object
class functions
42 43 44 45 46 |
# File 'lib/peach/device.rb', line 42 def self.destroy_all(xc:) Device.current_devices(xc: xc).each do |d| d.destroy end end |
.device_type(udid:, xc:) ⇒ Object
73 74 75 |
# File 'lib/peach/device.rb', line 73 def self.device_type(udid:, xc:) return xc.device_name(device_type_identifier(udid: udid, xc: xc)) end |
.device_type_identifier(udid:, xc:) ⇒ Object
68 69 70 71 |
# File 'lib/peach/device.rb', line 68 def self.device_type_identifier(udid:, xc:) plist = Plist.parse_xml("#{ENV['HOME']}/Library/Developer/CoreSimulator/Devices/#{udid}/device.plist") plist["deviceType"] end |
.load_devices ⇒ Object
77 78 79 |
# File 'lib/peach/device.rb', line 77 def self.load_devices `xcrun simctl list devices -j` end |
Instance Method Details
#==(o) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/peach/device.rb', line 33 def ==(o) o.class == self.class && o.name == @name && o.device_type == @device_type && o.runtime == runtime end |
#create ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/peach/device.rb', line 18 def create xc = XC.new runtime_id = xc.runtimes.key(@runtime) `xcrun simctl create \"#{@name}\" \"#{@device_type}\" \"#{runtime_id}\"` # reload everything to get the device. newDevices = Device.current_devices(xc: xc).select { |d| d == self } @udid = newDevices.first.udid end |
#destroy ⇒ Object
28 29 30 |
# File 'lib/peach/device.rb', line 28 def destroy `xcrun simctl delete #{@udid}` end |
#eql? ⇒ Object
32 |
# File 'lib/peach/device.rb', line 32 alias_method :eql?, :== |
#exists? ⇒ Boolean
13 14 15 16 |
# File 'lib/peach/device.rb', line 13 def exists? #could pass XC in? Make this a class function? Device.current_devices(xc: XC.new).include?(self) end |