class AppleSimUtils::Cmd

Attributes

bundle_id[R]
path[R]

Public Class Methods

new(bundle_id: nil) click to toggle source
# File lib/apple_sim_utils/command.rb, line 5
def initialize(bundle_id: nil)
  @path = get_command_path
  @bundle_id = bundle_id
end

Public Instance Methods

allow_all(device:, permissions:) click to toggle source
# File lib/apple_sim_utils/command.rb, line 10
def allow_all(device:, permissions:)
  raise 'You should set bundle_id' if @bundle_id.nil?

  p = permissions.map {|permission| permission + '=YES'}.join(',')
  run(%(--simulator '#{device}' --bundle #{@bundle_id} --setPermissions '#{p}'))
end
deny_all(device:, permissions:) click to toggle source
# File lib/apple_sim_utils/command.rb, line 17
def deny_all(device:, permissions:)
  raise 'You should set bundle_id' if @bundle_id.nil?

  p = permissions.map {|permission| permission + '=NO'}.join(',')
  run(%(--simulator '#{device}' --bundle #{@bundle_id} --setPermissions '#{p}'))
end
restart(device:) click to toggle source
# File lib/apple_sim_utils/command.rb, line 28
def restart(device:)
  run(%(--simulator '#{device}' --restartSB))
end
run(*command) click to toggle source
# File lib/apple_sim_utils/command.rb, line 32
def run(*command)
  return command.join(' ') if ENV['DRY_RUN']
  cmd = ([@path] + command).join(' ')

  sto, ste, status = Open3.capture3(cmd)
  if status.success?
    unless ste.empty?
      puts ste
      return ste
    end
    sto
  else
    puts ste
    raise(sto)
  end
end
set(device:, permission:, value:) click to toggle source
# File lib/apple_sim_utils/command.rb, line 24
def set(device:, permission:, value:)
  run(%(--simulator '#{device}' --bundle #{@bundle_id} --setPermissions '#{permission}=#{value}'))
end

Private Instance Methods

get_command_path() click to toggle source
# File lib/apple_sim_utils/command.rb, line 51
def get_command_path
  cmd = `which applesimutils`.strip
  return cmd unless cmd.empty?
  raise 'You should install applesimutils. Read https://github.com/wix/AppleSimulatorUtils'
end