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
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.
-
#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
-
#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
Resets the runtime.
-
#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.
-
#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.
15 16 17 18 |
# File 'lib/simctl/device.rb', line 15 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
231 232 233 234 235 236 237 238 239 240 |
# File 'lib/simctl/device.rb', line 231 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.
13 14 15 |
# File 'lib/simctl/device.rb', line 13 def is_available @is_available end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/simctl/device.rb', line 13 def name @name end |
#os ⇒ Object (readonly)
Returns the value of attribute os.
13 14 15 |
# File 'lib/simctl/device.rb', line 13 def os @os end |
#state ⇒ sym (readonly)
Returns the state of the device
209 210 211 |
# File 'lib/simctl/device.rb', line 209 def state @state end |
#udid ⇒ Object (readonly)
Returns the value of attribute udid.
13 14 15 |
# File 'lib/simctl/device.rb', line 13 def udid @udid end |
Instance Method Details
#==(other) ⇒ Object
225 226 227 228 229 |
# File 'lib/simctl/device.rb', line 225 def ==(other) return false if other.nil? return false unless other.is_a? Device other.udid == udid end |
#availability ⇒ Object
20 21 22 |
# File 'lib/simctl/device.rb', line 20 def availability is_available end |
#available? ⇒ Bool
Returns true/false if the device is available
28 29 30 |
# File 'lib/simctl/device.rb', line 28 def available? is_available !~ /unavailable/i end |
#boot ⇒ void
This method returns an undefined value.
Boots the device
35 36 37 |
# File 'lib/simctl/device.rb', line 35 def boot SimCtl.boot_device(self) end |
#delete ⇒ void
This method returns an undefined value.
Deletes the device
42 43 44 |
# File 'lib/simctl/device.rb', line 42 def delete SimCtl.delete_device(self) end |
#devicetype ⇒ SimCtl::DeviceType
Returns the device type
49 50 51 |
# File 'lib/simctl/device.rb', line 49 def devicetype @devicetype ||= SimCtl.devicetype(identifier: plist.deviceType) end |
#erase ⇒ void
This method returns an undefined value.
Erases the device
56 57 58 |
# File 'lib/simctl/device.rb', line 56 def erase SimCtl.erase_device(self) end |
#install(path) ⇒ void
This method returns an undefined value.
Installs an app on a device
64 65 66 |
# File 'lib/simctl/device.rb', line 64 def install(path) SimCtl.install_app(self, path) end |
#kill ⇒ void
This method returns an undefined value.
Kills the device
79 80 81 |
# File 'lib/simctl/device.rb', line 79 def kill SimCtl.kill_device(self) end |
#launch(scale = 1.0, opts = {}) ⇒ void
This method returns an undefined value.
Launches the Simulator
86 87 88 |
# File 'lib/simctl/device.rb', line 86 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
103 104 105 |
# File 'lib/simctl/device.rb', line 103 def launch_app(identifier, args = [], opts = {}) SimCtl.launch_app(self, identifier, args, opts) end |
#launchctl ⇒ Object
Returns the launchctl object
@ return [SimCtl::DeviceLaunchctl]
93 94 95 |
# File 'lib/simctl/device.rb', line 93 def launchctl @launchctl ||= DeviceLaunchctl.new(self) end |
#open_url(url) ⇒ void
This method returns an undefined value.
Opens the url on the device
120 121 122 |
# File 'lib/simctl/device.rb', line 120 def open_url(url) SimCtl.open_url(self, url) end |
#path ⇒ Object
124 125 126 |
# File 'lib/simctl/device.rb', line 124 def path @path ||= DevicePath.new(self) 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.
135 136 137 138 |
# File 'lib/simctl/device.rb', line 135 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
143 144 145 146 147 148 |
# File 'lib/simctl/device.rb', line 143 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
153 154 155 156 |
# File 'lib/simctl/device.rb', line 153 def rename(name) SimCtl.rename_device(self, name) @name = name end |
#reset ⇒ void
This method returns an undefined value.
Resets the device
161 162 163 |
# File 'lib/simctl/device.rb', line 161 def reset SimCtl.reset_device name, devicetype, runtime end |
#runtime ⇒ SimCtl::Runtime
Resets the runtime
168 169 170 |
# File 'lib/simctl/device.rb', line 168 def runtime @runtime ||= SimCtl.runtime(identifier: 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
179 180 181 |
# File 'lib/simctl/device.rb', line 179 def screenshot(file, opts = {}) SimCtl.screenshot(self, file, opts) end |
#settings ⇒ Object
Returns the settings object
@ return [SimCtl::DeviceSettings]
186 187 188 |
# File 'lib/simctl/device.rb', line 186 def settings @settings ||= DeviceSettings.new(path) end |
#shutdown ⇒ void
This method returns an undefined value.
Shuts down the runtime
193 194 195 |
# File 'lib/simctl/device.rb', line 193 def shutdown SimCtl.shutdown_device(self) end |
#spawn(path, args = [], opts = {}) ⇒ void
This method returns an undefined value.
Spawn a process on a device
202 203 204 |
# File 'lib/simctl/device.rb', line 202 def spawn(path, args = [], opts = {}) SimCtl.spawn(self, path, args, opts) end |
#terminate_app(identifier, args = []) ⇒ void
This method returns an undefined value.
Terminates an app on the given device
112 113 114 |
# File 'lib/simctl/device.rb', line 112 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
72 73 74 |
# File 'lib/simctl/device.rb', line 72 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
216 217 218 219 220 221 222 223 |
# File 'lib/simctl/device.rb', line 216 def wait(timeout = SimCtl.default_timeout) Timeout.timeout(timeout) do loop do break if yield SimCtl.device(udid: udid) end end reload end |