Sha256: 88a8f82622fde7879b73a6872658912d26e4f30c0941bf6591f00cf81d219e02

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

require 'kraken-mobile/models/device'

class WebDevice < Device
  #-------------------------------
  # Signaling
  #-------------------------------
  def create_inbox
    File.open(inbox_file_path, 'w')
  end

  def delete_inbox
    return unless File.exist? inbox_file_path

    File.delete(inbox_file_path)
  end

  def write_signal(signal)
    File.open(inbox_file_path, 'a') do |file|
      file.puts(signal)
    end
  end

  def read_signal(signal, timeout = K::DEFAULT_TIMEOUT_SECONDS)
    Timeout.timeout(timeout, RuntimeError) do
      sleep(1) until inbox_last_signal == signal
    end
  end

  #-------------------------------
  # More interface methods
  #-------------------------------
  def connected?
    true
  end

  def orientation
    K::WEB_PORTRAIT
  end

  def screen_size
    height = 0
    width = 0

    [height, width]
  end

  def sdk_version
    1.0 # Default
  end

  def type
    K::WEB_DEVICE
  end

  #-------------------------------
  # Random testing
  #-------------------------------
  def run_monkey_with_number_of_events(number_of_events)
    number_of_events # TODO, implement
  end

  def run_kraken_monkey_with_number_of_events(number_of_events)
    number_of_events # TODO, implement
  end

  #-------------------------------
  # Helpers
  #-------------------------------
  def self.factory_create
    WebDevice.new(
      id: SecureRandom.hex(10),
      model: 'Web'
    )
  end

  private

  def inbox_file_path
    ".#{@id}_#{K::INBOX_FILE_NAME}"
  end

  def inbox_last_signal
    lines = File.open(inbox_file_path).to_a
    lines.last&.strip
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kraken-mobile-1.0.5 lib/kraken-mobile/models/web_device.rb