class Aruba::CommandMonitor

The command monitor is part of the private API of Aruba.

@private

Attributes

announcer[R]
last_command_started[R]
last_command_stopped[R]
registered_commands[R]

Public Class Methods

new(opts = {}) click to toggle source
# File lib/aruba/platforms/command_monitor.rb, line 45
def initialize(opts = {})
  @registered_commands = []
  @announcer = opts.fetch(:announcer)

  @last_command_stopped = DefaultLastCommandStopped.new
  @last_command_started = DefaultLastCommandStarted.new
rescue KeyError => e
  raise ArgumentError, e.message
end

Public Instance Methods

all_output() click to toggle source

Get stderr and stdout of all commands

@return [String]

The stderr and stdout of all command which have run before
# File lib/aruba/platforms/command_monitor.rb, line 116
def all_output
  all_stdout << all_stderr
end
all_stderr() click to toggle source

Get stderr of all commands

@return [String]

The stderr of all command which have run before
# File lib/aruba/platforms/command_monitor.rb, line 106
def all_stderr
  registered_commands.each(&:stop)

  registered_commands.each_with_object("") { |e, a| a << e.stderr }
end
all_stdout() click to toggle source

Get stdout of all commands

@return [String]

The stdout of all command which have run before
# File lib/aruba/platforms/command_monitor.rb, line 96
def all_stdout
  registered_commands.each(&:stop)

  registered_commands.each_with_object("") { |e, a| a << e.stdout }
end
clear() click to toggle source

Clear list of known commands

# File lib/aruba/platforms/command_monitor.rb, line 85
def clear
  registered_commands.each(&:terminate)
  registered_commands.clear

  self
end
find(cmd) click to toggle source

Find command

@yield [Command]

This yields the found command
# File lib/aruba/platforms/command_monitor.rb, line 75
def find(cmd)
  cmd = cmd.commandline if cmd.respond_to? :commandline
  command = registered_commands.reverse.find { |c| c.commandline == cmd }

  raise CommandNotFoundError, "No command named '#{cmd}' has been started" if command.nil?

  command
end
last_command_started=(cmd) click to toggle source

Set last command started

@param [String] cmd

The commandline of the command
# File lib/aruba/platforms/command_monitor.rb, line 59
def last_command_started=(cmd)
  @last_command_started = find(cmd)
end
last_command_stopped=(cmd) click to toggle source

Set last command stopped

@param [String] cmd

The commandline of the command
# File lib/aruba/platforms/command_monitor.rb, line 67
def last_command_stopped=(cmd)
  @last_command_stopped = find(cmd)
end
register_command(cmd) click to toggle source

Register command to monitor

# File lib/aruba/platforms/command_monitor.rb, line 121
def register_command(cmd)
  registered_commands << cmd

  self
end