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



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.



55
56
57
# File 'lib/aruba/platforms/command_monitor.rb', line 55

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



118
119
120
# File 'lib/aruba/platforms/command_monitor.rb', line 118

def all_output
  all_stdout << all_stderr
end

#all_stderrString

Get stderr of all commands



108
109
110
111
112
# File 'lib/aruba/platforms/command_monitor.rb', line 108

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



98
99
100
101
102
# File 'lib/aruba/platforms/command_monitor.rb', line 98

def all_stdout
  registered_commands.each(&:stop)

  registered_commands.each_with_object('') { |e, a| a << e.stdout }
end

#clearObject

Clear list of known commands



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

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:



77
78
79
80
81
82
83
84
# File 'lib/aruba/platforms/command_monitor.rb', line 77

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



123
124
125
126
127
# File 'lib/aruba/platforms/command_monitor.rb', line 123

def register_command(cmd)
  registered_commands << cmd

  self
end