Class: SimCtl::Device
- Extended by:
- Gem::Deprecate
- Defined in:
- lib/simctl/device.rb
Instance Attribute Summary collapse
-
#is_available ⇒ Object
readonly
Returns the value of attribute is_available.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#os ⇒ Object
readonly
Returns the value of attribute os.
-
#state ⇒ sym
readonly
Returns the state of the device.
-
#udid ⇒ Object
readonly
Returns the value of attribute udid.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #availability ⇒ Object
-
#available? ⇒ Bool
Returns true/false if the device is available.
-
#boot ⇒ void
Boots the device.
-
#delete ⇒ void
Deletes the device.
-
#devicetype ⇒ SimCtl::DeviceType, String
Returns the device type.
-
#erase ⇒ void
Erases the device.
-
#initialize(args) ⇒ Device
constructor
A new instance of Device.
-
#install(path) ⇒ void
Installs an app on a device.
-
#keychain ⇒ SimCtl::keychain
Returns the keychain bar object.
-
#kill ⇒ void
Kills the device.
-
#launch(scale = 1.0, opts = {}) ⇒ void
Launches the Simulator.
-
#launch_app(identifier, args = [], opts = {}) ⇒ void
Launches an app in the given device.
-
#launchctl ⇒ Object
Returns the launchctl object.
- #method_missing(method_name, *args, &block) ⇒ Object
-
#open_url(url) ⇒ void
Opens the url on the device.
- #path ⇒ Object
-
#privacy(action, service, bundle) ⇒ void
Change privacy settings.
-
#ready? ⇒ Bool
Returns true/false if the device is ready Uses [SimCtl::DeviceLaunchctl] to look for certain services being running.
-
#reload ⇒ void
Reloads the device information.
-
#rename(name) ⇒ void
Renames the device.
-
#reset ⇒ void
Resets the device.
-
#runtime ⇒ SimCtl::Runtime, String
Returns the runtime object.
-
#screenshot(file, opts = {}) ⇒ void
Saves a screenshot to a file.
-
#settings ⇒ Object
Returns the settings object.
-
#shutdown ⇒ void
Shuts down the runtime.
-
#spawn(path, args = [], opts = {}) ⇒ void
Spawn a process on a device.
-
#status_bar ⇒ SimCtl::StatusBar
Returns the status bar object.
-
#terminate_app(identifier, args = []) ⇒ void
Terminates an app on the given device.
-
#uninstall(app_id) ⇒ void
Uninstall an app from a device.
-
#wait(timeout = SimCtl.default_timeout) ⇒ void
Reloads the device until the given block returns true.
Constructor Details
#initialize(args) ⇒ Device
Returns a new instance of Device.
17 18 19 20 |
# File 'lib/simctl/device.rb', line 17 def initialize(args) args['is_available'] = args.delete('isAvailable') super end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
268 269 270 271 272 273 274 275 276 277 |
# File 'lib/simctl/device.rb', line 268 def method_missing(method_name, *args, &block) if method_name[-1] == '!' new_method_name = method_name.to_s.chop.to_sym if respond_to?(new_method_name) warn "[#{Kernel.caller.first}] `#{method_name}` is deprecated. Please use `#{new_method_name}` instead." return send(new_method_name, &block) end end super end |
Instance Attribute Details
#is_available ⇒ Object (readonly)
Returns the value of attribute is_available.
15 16 17 |
# File 'lib/simctl/device.rb', line 15 def is_available @is_available end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/simctl/device.rb', line 15 def name @name end |
#os ⇒ Object (readonly)
Returns the value of attribute os.
15 16 17 |
# File 'lib/simctl/device.rb', line 15 def os @os end |
#state ⇒ sym (readonly)
Returns the state of the device
239 240 241 |
# File 'lib/simctl/device.rb', line 239 def state @state end |
#udid ⇒ Object (readonly)
Returns the value of attribute udid.
15 16 17 |
# File 'lib/simctl/device.rb', line 15 def udid @udid end |
Instance Method Details
#==(other) ⇒ Object
262 263 264 265 266 |
# File 'lib/simctl/device.rb', line 262 def ==(other) return false if other.nil? return false unless other.is_a? Device other.udid == udid end |
#availability ⇒ Object
22 23 24 |
# File 'lib/simctl/device.rb', line 22 def availability is_available end |
#available? ⇒ Bool
Returns true/false if the device is available
30 31 32 33 34 35 36 37 |
# File 'lib/simctl/device.rb', line 30 def available? case is_available when String is_available !~ /unavailable/i else is_available end end |
#boot ⇒ void
This method returns an undefined value.
Boots the device
42 43 44 |
# File 'lib/simctl/device.rb', line 42 def boot SimCtl.boot_device(self) end |
#delete ⇒ void
This method returns an undefined value.
Deletes the device
49 50 51 |
# File 'lib/simctl/device.rb', line 49 def delete SimCtl.delete_device(self) end |
#devicetype ⇒ SimCtl::DeviceType, String
Returns the device type
56 57 58 59 60 |
# File 'lib/simctl/device.rb', line 56 def devicetype @devicetype ||= SimCtl.devicetype(identifier: plist.deviceType) rescue plist.deviceType end |
#erase ⇒ void
This method returns an undefined value.
Erases the device
65 66 67 |
# File 'lib/simctl/device.rb', line 65 def erase SimCtl.erase_device(self) end |
#install(path) ⇒ void
This method returns an undefined value.
Installs an app on a device
73 74 75 |
# File 'lib/simctl/device.rb', line 73 def install(path) SimCtl.install_app(self, path) end |
#keychain ⇒ SimCtl::keychain
Returns the keychain bar object
109 110 111 |
# File 'lib/simctl/device.rb', line 109 def keychain @keychain ||= SimCtl::Keychain.new(self) end |
#kill ⇒ void
This method returns an undefined value.
Kills the device
88 89 90 |
# File 'lib/simctl/device.rb', line 88 def kill SimCtl.kill_device(self) end |
#launch(scale = 1.0, opts = {}) ⇒ void
This method returns an undefined value.
Launches the Simulator
95 96 97 |
# File 'lib/simctl/device.rb', line 95 def launch(scale = 1.0, opts = {}) SimCtl.launch_device(self, scale, opts) end |
#launch_app(identifier, args = [], opts = {}) ⇒ void
This method returns an undefined value.
Launches an app in the given device
119 120 121 |
# File 'lib/simctl/device.rb', line 119 def launch_app(identifier, args = [], opts = {}) SimCtl.launch_app(self, identifier, args, opts) end |
#launchctl ⇒ Object
Returns the launchctl object
@ return [SimCtl::DeviceLaunchctl]
102 103 104 |
# File 'lib/simctl/device.rb', line 102 def launchctl @launchctl ||= DeviceLaunchctl.new(self) end |
#open_url(url) ⇒ void
This method returns an undefined value.
Opens the url on the device
136 137 138 |
# File 'lib/simctl/device.rb', line 136 def open_url(url) SimCtl.open_url(self, url) end |
#path ⇒ Object
140 141 142 |
# File 'lib/simctl/device.rb', line 140 def path @path ||= DevicePath.new(self) end |
#privacy(action, service, bundle) ⇒ void
This method returns an undefined value.
Change privacy settings
152 153 154 |
# File 'lib/simctl/device.rb', line 152 def privacy(action, service, bundle) SimCtl.privacy(self, action, service, bundle) end |
#ready? ⇒ Bool
Returns true/false if the device is ready Uses [SimCtl::DeviceLaunchctl] to look for certain services being running.
Unfortunately the ‘booted’ state does not mean the Simulator is ready for installing or launching applications.
163 164 165 166 |
# File 'lib/simctl/device.rb', line 163 def ready? running_services = launchctl.list.reject { |service| service.pid.to_i == 0 }.map(&:name) (required_services_for_ready - running_services).empty? end |
#reload ⇒ void
This method returns an undefined value.
Reloads the device information
171 172 173 174 175 176 |
# File 'lib/simctl/device.rb', line 171 def reload device = SimCtl.device(udid: udid) device.instance_variables.each do |ivar| instance_variable_set(ivar, device.instance_variable_get(ivar)) end end |
#rename(name) ⇒ void
This method returns an undefined value.
Renames the device
181 182 183 184 |
# File 'lib/simctl/device.rb', line 181 def rename(name) SimCtl.rename_device(self, name) @name = name end |
#reset ⇒ void
This method returns an undefined value.
Resets the device
189 190 191 |
# File 'lib/simctl/device.rb', line 189 def reset SimCtl.reset_device name, devicetype, runtime end |
#runtime ⇒ SimCtl::Runtime, String
Returns the runtime object
196 197 198 199 200 |
# File 'lib/simctl/device.rb', line 196 def runtime @runtime ||= SimCtl.runtime(identifier: plist.runtime) rescue plist.runtime end |
#screenshot(file, opts = {}) ⇒ void
This method returns an undefined value.
Saves a screenshot to a file
-
type: Can be png, tiff, bmp, gif, jpeg (default is png)
-
display: Can be main or tv for iOS, tv for tvOS and main for watchOS
209 210 211 |
# File 'lib/simctl/device.rb', line 209 def screenshot(file, opts = {}) SimCtl.screenshot(self, file, opts) end |
#settings ⇒ Object
Returns the settings object
@ return [SimCtl::DeviceSettings]
216 217 218 |
# File 'lib/simctl/device.rb', line 216 def settings @settings ||= DeviceSettings.new(path) end |
#shutdown ⇒ void
This method returns an undefined value.
Shuts down the runtime
223 224 225 |
# File 'lib/simctl/device.rb', line 223 def shutdown SimCtl.shutdown_device(self) end |
#spawn(path, args = [], opts = {}) ⇒ void
This method returns an undefined value.
Spawn a process on a device
232 233 234 |
# File 'lib/simctl/device.rb', line 232 def spawn(path, args = [], opts = {}) SimCtl.spawn(self, path, args, opts) end |
#status_bar ⇒ SimCtl::StatusBar
Returns the status bar object
246 247 248 |
# File 'lib/simctl/device.rb', line 246 def @status_bar ||= SimCtl::StatusBar.new(self) end |
#terminate_app(identifier, args = []) ⇒ void
This method returns an undefined value.
Terminates an app on the given device
128 129 130 |
# File 'lib/simctl/device.rb', line 128 def terminate_app(identifier, args = []) SimCtl.terminate_app(self, identifier, args) end |
#uninstall(app_id) ⇒ void
This method returns an undefined value.
Uninstall an app from a device
81 82 83 |
# File 'lib/simctl/device.rb', line 81 def uninstall(app_id) SimCtl.uninstall_app(self, app_id) end |
#wait(timeout = SimCtl.default_timeout) ⇒ void
This method returns an undefined value.
Reloads the device until the given block returns true
253 254 255 256 257 258 259 260 |
# File 'lib/simctl/device.rb', line 253 def wait(timeout = SimCtl.default_timeout) Timeout.timeout(timeout) do loop do break if yield SimCtl.device(udid: udid) end end reload end |