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
- .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
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/israkel/device.rb', line 34 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
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/israkel/device.rb', line 47 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 |
.sim_root_path ⇒ Object
102 103 104 |
# File 'lib/israkel/device.rb', line 102 def self.sim_root_path File.join(ENV['HOME'], 'Library', 'Developer', 'CoreSimulator', 'Devices') end |
.stop ⇒ Object
30 31 32 |
# File 'lib/israkel/device.rb', line 30 def self.stop system 'killall', '-m', '-TERM', 'iOS Simulator' end |
Instance Method Details
#allow_addressbook_access(bundle_id) ⇒ Object
63 64 65 |
# File 'lib/israkel/device.rb', line 63 def allow_addressbook_access(bundle_id) allow_tcc_access('kTCCServiceAddressBook', bundle_id) end |
#allow_gps_access(bundle_id) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/israkel/device.rb', line 71 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
67 68 69 |
# File 'lib/israkel/device.rb', line 67 def allow_photos_access(bundle_id) allow_tcc_access('kTCCServicePhotos', bundle_id) end |
#edit_global_preferences(&block) ⇒ Object
110 111 112 113 |
# File 'lib/israkel/device.rb', line 110 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
115 116 117 118 |
# File 'lib/israkel/device.rb', line 115 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
106 107 108 |
# File 'lib/israkel/device.rb', line 106 def os runtime.gsub('com.apple.CoreSimulator.SimRuntime.iOS-', '').gsub('-', '.') end |
#reset ⇒ Object
97 98 99 100 |
# File 'lib/israkel/device.rb', line 97 def reset FileUtils.rm_rf File.join(path) FileUtils.mkdir File.join(path) end |
#set_language(language) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/israkel/device.rb', line 79 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
93 94 95 |
# File 'lib/israkel/device.rb', line 93 def start system "ios-sim start --devicetypeid \"#{device_type}\"" end |
#tcc_path ⇒ Object
120 121 122 |
# File 'lib/israkel/device.rb', line 120 def tcc_path File.join(path, 'Library', 'TCC', 'TCC.db') end |
#to_s ⇒ Object
59 60 61 |
# File 'lib/israkel/device.rb', line 59 def to_s "#{name} #{pretty_runtime}" end |