Class: Aruba::CommandMonitor

Inherits:
Object
  • Object
show all
Defined in:
lib/aruba/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.



47
48
49
50
51
52
53
54
55
# File 'lib/aruba/command_monitor.rb', line 47

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.



17
18
19
# File 'lib/aruba/command_monitor.rb', line 17

def last_command_started
  @last_command_started
end

#last_command_stoppedObject

Returns the value of attribute last_command_stopped.



17
18
19
# File 'lib/aruba/command_monitor.rb', line 17

def last_command_stopped
  @last_command_stopped
end

#registered_commandsObject (readonly)

Returns the value of attribute registered_commands.



17
18
19
# File 'lib/aruba/command_monitor.rb', line 17

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



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

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



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

def all_stderr
  registered_commands.each(&:stop)

  registered_commands.map(&:stderr).join
end

#all_stdoutString

Get stdout of all commands

Returns:

  • (String)

    The stdout of all command which have run before



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

def all_stdout
  registered_commands.each(&:stop)

  registered_commands.map(&:stdout).join
end

#clearObject

Clear list of known commands



87
88
89
90
91
92
# File 'lib/aruba/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/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/command_monitor.rb', line 123

def register_command(cmd)
  registered_commands << cmd

  self
end