Class: SimCtl::Device

Inherits:
Object
  • Object
show all
Extended by:
Gem::Deprecate
Defined in:
lib/simctl/device.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_availableObject (readonly)

Returns the value of attribute is_available.



13
14
15
# File 'lib/simctl/device.rb', line 13

def is_available
  @is_available
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/simctl/device.rb', line 13

def name
  @name
end

#osObject (readonly)

Returns the value of attribute os.



13
14
15
# File 'lib/simctl/device.rb', line 13

def os
  @os
end

#statesym (readonly)

Returns the state of the device

Returns:

  • (sym)


209
210
211
# File 'lib/simctl/device.rb', line 209

def state
  @state
end

#udidObject (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

#availabilityObject



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

Returns:

  • (Bool)


28
29
30
# File 'lib/simctl/device.rb', line 28

def available?
  is_available !~ /unavailable/i
end

#bootvoid

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

#deletevoid

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

#devicetypeSimCtl::DeviceType

Returns the device type

Returns:



49
50
51
# File 'lib/simctl/device.rb', line 49

def devicetype
  @devicetype ||= SimCtl.devicetype(identifier: plist.deviceType)
end

#erasevoid

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

Parameters:

  • path

    Absolute path to the app that should be installed



64
65
66
# File 'lib/simctl/device.rb', line 64

def install(path)
  SimCtl.install_app(self, path)
end

#killvoid

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

Parameters:

  • opts (Hash) (defaults to: {})

    options hash - ‘{ wait_for_debugger: true/false }`

  • identifier (String)

    the app identifier

  • args (Array) (defaults to: [])

    optional launch arguments



103
104
105
# File 'lib/simctl/device.rb', line 103

def launch_app(identifier, args = [], opts = {})
  SimCtl.launch_app(self, identifier, args, opts)
end

#launchctlObject

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

Parameters:

  • url (String)

    The url to be opened on the device



120
121
122
# File 'lib/simctl/device.rb', line 120

def open_url(url)
  SimCtl.open_url(self, url)
end

#pathObject



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.

Returns:

  • (Bool)


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

#reloadvoid

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

#resetvoid

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

#runtimeSimCtl::Runtime

Resets the runtime

Returns:



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

Parameters:

  • file

    Path where the screenshot should be saved to

  • opts (defaults to: {})

    Optional hash that supports two keys:



179
180
181
# File 'lib/simctl/device.rb', line 179

def screenshot(file, opts = {})
  SimCtl.screenshot(self, file, opts)
end

#settingsObject

Returns the settings object

@ return [SimCtl::DeviceSettings]



186
187
188
# File 'lib/simctl/device.rb', line 186

def settings
  @settings ||= DeviceSettings.new(path)
end

#shutdownvoid

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

Parameters:

  • path (String)

    path to executable

  • args (Array) (defaults to: [])

    arguments for the executable



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

Parameters:

  • identifier (String)

    the app identifier

  • args (Array) (defaults to: [])

    optional terminate arguments



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

Parameters:

  • app_id

    App identifier of the app that should be uninstalled



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