Class: Device
- Inherits:
-
Object
- Object
- Device
- Defined in:
- lib/israkel/device.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#runtime ⇒ Object
Returns the value of attribute runtime.
-
#state ⇒ Object
Returns the value of attribute state.
-
#type ⇒ Object
Returns the value of attribute type.
-
#UUID ⇒ Object
Returns the value of attribute UUID.
Class Method Summary collapse
- .all ⇒ Object
- .edit_plist(path) {|content || {}| ... } ⇒ Object
- .from_hash(hash) ⇒ Object
- .from_plist(plist) ⇒ Object
- .shutdown_devices ⇒ Object
- .sim_root_path ⇒ Object
- .stop ⇒ Object
- .with_sdk_and_type(sdk_version, type) ⇒ Object
Instance Method Summary collapse
- #allow_addressbook_access(bundle_id) ⇒ Object
- #allow_gps_access(bundle_id) ⇒ Object
- #allow_photos_access(bundle_id) ⇒ Object
- #edit_global_preferences(&block) ⇒ Object
- #edit_preferences(&block) ⇒ Object
-
#initialize(uuid, type, name, state, runtime) ⇒ Device
constructor
A new instance of Device.
- #os ⇒ Object
- #reset ⇒ Object
- #set_language(language) ⇒ Object
- #start ⇒ Object
- #tcc_path ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(uuid, type, name, state, runtime) ⇒ Device
Returns a new instance of Device.
7 8 9 10 11 12 13 |
# File 'lib/israkel/device.rb', line 7 def initialize(uuid, type, name, state, runtime) @UUID = uuid @type = type @name = name @state = state @runtime = runtime end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/israkel/device.rb', line 5 def name @name end |
#runtime ⇒ Object
Returns the value of attribute runtime.
5 6 7 |
# File 'lib/israkel/device.rb', line 5 def runtime @runtime end |
#state ⇒ Object
Returns the value of attribute state.
5 6 7 |
# File 'lib/israkel/device.rb', line 5 def state @state end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/israkel/device.rb', line 5 def type @type end |
#UUID ⇒ Object
Returns the value of attribute UUID.
5 6 7 |
# File 'lib/israkel/device.rb', line 5 def UUID @UUID end |
Class Method Details
.all ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/israkel/device.rb', line 41 def self.all devices = [] dirs = Dir.entries(Device.sim_root_path).reject { |entry| File.directory? entry } dirs.sort.each do |simulator_dir| plist_path = "#{Device.sim_root_path}/#{simulator_dir}/device.plist" if File.exists?(plist_path) plist = CFPropertyList::List.new(:file => plist_path) devices << Device.from_plist(plist) end end devices end |
.edit_plist(path) {|content || {}| ... } ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/israkel/device.rb', line 54 def self.edit_plist(path, &block) if File.exists?(path) plist = CFPropertyList::List.new(:file => path) content = CFPropertyList.native_types(plist.value) end yield content || {} if plist plist.value = CFPropertyList.guess(content) plist.save(path, CFPropertyList::List::FORMAT_BINARY) end end |
.from_hash(hash) ⇒ Object
15 16 17 |
# File 'lib/israkel/device.rb', line 15 def self.from_hash(hash) self.new(hash['UDID'], hash['deviceType'], hash['name'], hash['state'], hash['runtime']) end |
.from_plist(plist) ⇒ Object
19 20 21 |
# File 'lib/israkel/device.rb', line 19 def self.from_plist(plist) self.from_hash(CFPropertyList.native_types(plist.value)) end |
.shutdown_devices ⇒ Object
35 36 37 38 39 |
# File 'lib/israkel/device.rb', line 35 def self.shutdown_devices SIMCTL.booted_devices_uuids.each do |uuid| SIMCTL.shutdown(uuid) end end |
.sim_root_path ⇒ Object
108 109 110 |
# File 'lib/israkel/device.rb', line 108 def self.sim_root_path File.join(ENV['HOME'], 'Library', 'Developer', 'CoreSimulator', 'Devices') end |
.stop ⇒ Object
30 31 32 33 |
# File 'lib/israkel/device.rb', line 30 def self.stop self.shutdown_devices system 'killall', '-m', '-TERM', 'iOS Simulator' end |
Instance Method Details
#allow_addressbook_access(bundle_id) ⇒ Object
70 71 72 |
# File 'lib/israkel/device.rb', line 70 def allow_addressbook_access(bundle_id) allow_tcc_access('kTCCServiceAddressBook', bundle_id) end |
#allow_gps_access(bundle_id) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/israkel/device.rb', line 78 def allow_gps_access(bundle_id) directory = File.join(path, 'Library', 'Caches', 'locationd') FileUtils.mkdir_p(directory) unless Dir.exists?(directory) Device.edit_plist(File.join(directory, 'clients.plist')) do |content| set_gps_access(content, bundle_id) end end |
#allow_photos_access(bundle_id) ⇒ Object
74 75 76 |
# File 'lib/israkel/device.rb', line 74 def allow_photos_access(bundle_id) allow_tcc_access('kTCCServicePhotos', bundle_id) end |
#edit_global_preferences(&block) ⇒ Object
116 117 118 119 |
# File 'lib/israkel/device.rb', line 116 def edit_global_preferences(&block) pref_path = File.join(path, 'Library', 'Preferences') Device.edit_plist( File.join(pref_path, '.GlobalPreferences.plist'), &block ) end |
#edit_preferences(&block) ⇒ Object
121 122 123 124 |
# File 'lib/israkel/device.rb', line 121 def edit_preferences(&block) pref_path = File.join(path, 'Library', 'Preferences') Device.edit_plist( File.join(pref_path, 'com.apple.Preferences.plist'), &block ) end |
#os ⇒ Object
112 113 114 |
# File 'lib/israkel/device.rb', line 112 def os runtime.gsub('com.apple.CoreSimulator.SimRuntime.iOS-', '').gsub('-', '.') end |
#reset ⇒ Object
104 105 106 |
# File 'lib/israkel/device.rb', line 104 def reset SIMCTL.erase @UUID end |
#set_language(language) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/israkel/device.rb', line 86 def set_language(language) edit_global_preferences do |p| if p['AppleLanguages'] if p['AppleLanguages'].include?(language) p['AppleLanguages'].unshift(language).uniq! else fail "#{language} is not a valid language" end else p['AppleLanguages'] = [language] end end end |
#start ⇒ Object
100 101 102 |
# File 'lib/israkel/device.rb', line 100 def start system "ios-sim start --devicetypeid \"#{device_type}\"" end |
#tcc_path ⇒ Object
126 127 128 |
# File 'lib/israkel/device.rb', line 126 def tcc_path File.join(path, 'Library', 'TCC', 'TCC.db') end |
#to_s ⇒ Object
66 67 68 |
# File 'lib/israkel/device.rb', line 66 def to_s "#{name} #{pretty_runtime}" end |