Class: Aruba::CommandMonitor

Inherits:
Object
  • Object
show all
Defined in:
lib/aruba/platforms/command_monitor.rb

Overview

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

Defined Under Namespace

Classes: DefaultLastCommandStarted, DefaultLastCommandStopped

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ CommandMonitor

Returns a new instance of CommandMonitor.



45
46
47
48
49
50
51
52
53
# 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

Instance Attribute Details

#last_command_startedObject

Returns the value of attribute last_command_started.



15
16
17
# File 'lib/aruba/platforms/command_monitor.rb', line 15

def last_command_started
  @last_command_started
end

#last_command_stoppedObject

Returns the value of attribute last_command_stopped.



15
16
17
# File 'lib/aruba/platforms/command_monitor.rb', line 15

def last_command_stopped
  @last_command_stopped
end

#registered_commandsObject (readonly)

Returns the value of attribute registered_commands.



15
16
17
# File 'lib/aruba/platforms/command_monitor.rb', line 15

def registered_commands
  @registered_commands
end

Instance Method Details

#all_outputString

Get stderr and stdout of all commands

Returns:

  • (String)

    The stderr and stdout of all command which have run before



116
117
118
# File 'lib/aruba/platforms/command_monitor.rb', line 116

def all_output
  all_stdout << all_stderr
end

#all_stderrString

Get stderr of all commands

Returns:

  • (String)

    The stderr of all command which have run before



106
107
108
109
110
# 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_stdoutString

Get stdout of all commands

Returns:

  • (String)

    The stdout of all command which have run before



96
97
98
99
100
# 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

#clearObject

Clear list of known commands



85
86
87
88
89
90
# File 'lib/aruba/platforms/command_monitor.rb', line 85

def clear
  registered_commands.each(&:terminate)
  registered_commands.clear

  self
end

#find(cmd) {|Command| ... } ⇒ Object

Find command

Yields:

  • (Command)

    This yields the found command

Raises:



75
76
77
78
79
80
81
82
# 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

#register_command(cmd) ⇒ Object

Register command to monitor



121
122
123
124
125
# File 'lib/aruba/platforms/command_monitor.rb', line 121

def register_command(cmd)
  registered_commands << cmd

  self
end