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, xc: XC.new) ⇒ Device
constructor
A new instance of Device.
Constructor Details
#initialize(name:, device_type:, runtime:, udid: nil, xc: XC.new) ⇒ Device
Returns a new instance of Device.
6 7 8 9 10 11 12 |
# File 'lib/peach/device.rb', line 6 def initialize(name:, device_type:, runtime:, udid: nil, xc: XC.new) @name = name @device_type = device_type @runtime = runtime @udid = udid @xc = xc 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
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/peach/device.rb', line 53 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, xc: xc) end end devices end |
.destroy_all(xc:) ⇒ Object
class functions
47 48 49 50 51 |
# File 'lib/peach/device.rb', line 47 def self.destroy_all(xc:) Device.current_devices(xc: xc).each do |d| d.destroy end end |
.device_type(udid:, xc:) ⇒ Object
78 79 80 |
# File 'lib/peach/device.rb', line 78 def self.device_type(udid:, xc:) return xc.device_name(device_type_identifier(udid: udid, xc: xc)) end |
.device_type_identifier(udid:, xc:) ⇒ Object
73 74 75 76 |
# File 'lib/peach/device.rb', line 73 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
82 83 84 |
# File 'lib/peach/device.rb', line 82 def self.load_devices `xcrun simctl list devices -j` end |
Instance Method Details
#==(o) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/peach/device.rb', line 38 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 27 28 29 30 31 |
# File 'lib/peach/device.rb', line 18 def create runtime_id = @xc.runtimes.key(@runtime) if @xc.runtime_invalid(@runtime) puts "Unable to create #{@name}. Invalid runtime: #{@runtime}. Run \"xcrun simctl list runtimes\" to list available runtimes" elsif @xc.device_type_invalid(@device_type) puts "Unable to create #{@name}. Invalid device_type: #{@device_type}. Run \"xcrun simctl list devicetypes\" to list available devicetypes" else `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 end |
#destroy ⇒ Object
33 34 35 |
# File 'lib/peach/device.rb', line 33 def destroy `xcrun simctl delete #{@udid}` end |
#eql? ⇒ Object
37 |
# File 'lib/peach/device.rb', line 37 alias_method :eql?, :== |
#exists? ⇒ Boolean
14 15 16 |
# File 'lib/peach/device.rb', line 14 def exists? Device.current_devices(xc: @xc).include?(self) end |