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
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/peach/device.rb', line 50 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
43 44 45 46 47 48 |
# File 'lib/peach/device.rb', line 43 def self.destroy_all(xc:) devices = Device.current_devices(xc: xc) || [] devices.each do |d| d.destroy end end |
.device_type(udid:, xc:) ⇒ Object
75 76 77 78 |
# File 'lib/peach/device.rb', line 75 def self.device_type(udid:, xc:) device_type_identifier = device_type_identifier(udid: udid, xc: xc) xc.device_name(device_type_identifier) end |
.device_type_identifier(udid:, xc:) ⇒ Object
70 71 72 73 |
# File 'lib/peach/device.rb', line 70 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
80 81 82 |
# File 'lib/peach/device.rb', line 80 def self.load_devices `xcrun simctl list devices -j` end |
Instance Method Details
#==(o) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/peach/device.rb', line 34 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 |
# 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 @udid = `xcrun simctl create \"#{@name}\" \"#{@device_type}\" \"#{runtime_id}\"`.strip end end |
#destroy ⇒ Object
29 30 31 |
# File 'lib/peach/device.rb', line 29 def destroy `xcrun simctl delete #{@udid}` end |
#eql? ⇒ Object
33 |
# File 'lib/peach/device.rb', line 33 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 |