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.



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

Returns the value of attribute is_available.



15
16
17
# File 'lib/simctl/device.rb', line 15

def is_available
  @is_available
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/simctl/device.rb', line 15

def name
  @name
end

#osObject (readonly)

Returns the value of attribute os.



15
16
17
# File 'lib/simctl/device.rb', line 15

def os
  @os
end

#statesym (readonly)

Returns the state of the device

Returns:

  • (sym)


239
240
241
# File 'lib/simctl/device.rb', line 239

def state
  @state
end

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

#availabilityObject



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

Returns:

  • (Bool)


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

#bootvoid

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

#deletevoid

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

#devicetypeSimCtl::DeviceType, String

Returns the device type

Returns:



56
57
58
59
60
# File 'lib/simctl/device.rb', line 56

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

#erasevoid

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

Parameters:

  • path

    Absolute path to the app that should be installed



73
74
75
# File 'lib/simctl/device.rb', line 73

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

#keychainSimCtl::keychain

Returns the keychain bar object

Returns:

  • (SimCtl::keychain)


109
110
111
# File 'lib/simctl/device.rb', line 109

def keychain
  @keychain ||= SimCtl::Keychain.new(self)
end

#killvoid

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

Parameters:

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

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

  • identifier (String)

    the app identifier

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

    optional launch arguments



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

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

#launchctlObject

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

Parameters:

  • url (String)

    The url to be opened on the device



136
137
138
# File 'lib/simctl/device.rb', line 136

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

#pathObject



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

Parameters:

  • action (String)

    grant, revoke, reset

  • service (String)

    all, calendar, contacts-limited, contacts, location, location-always, photos-add, photos, media-library, microphone, motion, reminders, siri

  • bundle (String)

    bundle identifier



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.

Returns:

  • (Bool)


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

#reloadvoid

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

#resetvoid

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

#runtimeSimCtl::Runtime, String

Returns the runtime object

Returns:



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

Parameters:

  • file

    Path where the screenshot should be saved to

  • opts (defaults to: {})

    Optional hash that supports two keys:



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

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

#settingsObject

Returns the settings object

@ return [SimCtl::DeviceSettings]



216
217
218
# File 'lib/simctl/device.rb', line 216

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

#shutdownvoid

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

Parameters:

  • path (String)

    path to executable

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

    arguments for the executable



232
233
234
# File 'lib/simctl/device.rb', line 232

def spawn(path, args = [], opts = {})
  SimCtl.spawn(self, path, args, opts)
end

#status_barSimCtl::StatusBar

Returns the status bar object

Returns:



246
247
248
# File 'lib/simctl/device.rb', line 246

def status_bar
  @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

Parameters:

  • identifier (String)

    the app identifier

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

    optional terminate arguments



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

Parameters:

  • app_id

    App identifier of the app that should be uninstalled



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