class DeviceProcess

Abstract class

Attributes

device[RW]
id[RW]
test_scenario[RW]

Public Class Methods

directory() click to toggle source
# File lib/kraken-mobile/device_process.rb, line 82
def self.directory
  return [] unless File.exist?(K::DIRECTORY_PATH)

  directory = nil
  File.open(K::DIRECTORY_PATH, 'r') do |file|
    directory = file.each_line.map(&:to_s).map(&:strip)
  end

  directory || []
end
new(id:, device:, test_scenario:) click to toggle source
# File lib/kraken-mobile/device_process.rb, line 12
def initialize(id:, device:, test_scenario:)
  @id = id
  @device = device
  @test_scenario = test_scenario
end
notify_process_state(process_id:, state:) click to toggle source
# File lib/kraken-mobile/device_process.rb, line 101
def self.notify_process_state(process_id:, state:)
  raise 'ERROR: Process id can\'t be nil.' if process_id.nil?

  file_path = K::PROCESS_STATE_FILE_PATH[state]
  raise 'ERROR: State does not exist.' if file_path.nil?

  File.open(file_path, 'a') do |file|
    file.puts(process_id)
  end
end
processes_in_state(state) click to toggle source
# File lib/kraken-mobile/device_process.rb, line 112
def self.processes_in_state(state)
  file_path = K::PROCESS_STATE_FILE_PATH[state]
  return [] if file_path.nil?
  return [] unless File.exist?(file_path)

  devices_ready = nil
  File.open(file_path, 'r') do |file|
    devices_ready = file.each_line.map(&:to_s).map(&:strip)
  end

  devices_ready || []
end
registered_process_ids() click to toggle source
# File lib/kraken-mobile/device_process.rb, line 93
def self.registered_process_ids
  directory = DeviceProcess.directory
  directory.map do |entry|
    info = entry.strip.split(K::SEPARATOR)
    info[0]
  end.compact.uniq
end

Public Instance Methods

after_execute() click to toggle source
# File lib/kraken-mobile/device_process.rb, line 29
def after_execute
  raise 'ERROR: after_execute not implemented.'
end
before_execute() click to toggle source
# File lib/kraken-mobile/device_process.rb, line 21
def before_execute
  raise 'ERROR: before_execute not implemented.'
end
execute() click to toggle source
# File lib/kraken-mobile/device_process.rb, line 25
def execute
  raise 'ERROR: execute not implemented.'
end
exporting_command_for_environment_variables(variables = {}) click to toggle source
# File lib/kraken-mobile/device_process.rb, line 71
def exporting_command_for_environment_variables(variables = {})
  commands = variables.map do |key, value|
    if running_on_windows?
      "(SET \"#{key}=#{value}\")"
    else
      "#{key}=#{value};export #{key}"
    end
  end
  commands.join(terminal_command_separator)
end
notify_ready_to_start() click to toggle source
# File lib/kraken-mobile/device_process.rb, line 61
def notify_ready_to_start
  File.open(K::DIRECTORY_PATH, 'a') do |file|
    file.puts("#{id}#{K::SEPARATOR}#{device}")
  end
end
register_process_to_directory() click to toggle source
# File lib/kraken-mobile/device_process.rb, line 42
def register_process_to_directory
  File.open(K::DIRECTORY_PATH, 'a') do |file|
    file.puts("#{id}#{K::SEPARATOR}#{device}")
  end
end
run() click to toggle source
# File lib/kraken-mobile/device_process.rb, line 33
def run
  before_execute
  execute
  after_execute
end
running_on_windows?() click to toggle source
# File lib/kraken-mobile/device_process.rb, line 67
def running_on_windows?
  RbConfig::CONFIG['host_os'] =~ /cygwin|mswin|mingw|bccwin|wince|emx/
end
terminal_command_separator() click to toggle source
# File lib/kraken-mobile/device_process.rb, line 125
def terminal_command_separator
  return ' & ' if running_on_windows?

  ';'
end
unregister_process_from_directory() click to toggle source
# File lib/kraken-mobile/device_process.rb, line 48
def unregister_process_from_directory
  File.open(K::DIRECTORY_PATH, 'r') do |f|
    File.open("#{K::DIRECTORY_PATH}.tmp", 'w') do |f2|
      f.each_line do |line|
        f2.write(line) unless line.start_with?(
          "#{id}#{K::SEPARATOR}#{device}"
        )
      end
    end
  end
  FileUtils.mv("#{K::DIRECTORY_PATH}.tmp", K::DIRECTORY_PATH)
end