Class: Aruba::CommandMonitor
- Inherits:
-
Object
- Object
- Aruba::CommandMonitor
- 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
-
#last_command_started ⇒ Object
Returns the value of attribute last_command_started.
-
#last_command_stopped ⇒ Object
Return the last command stopped.
-
#registered_commands ⇒ Object
readonly
Returns the value of attribute registered_commands.
Instance Method Summary collapse
-
#all_output ⇒ String
Get stderr and stdout of all commands.
-
#all_stderr ⇒ String
Get stderr of all commands.
-
#all_stdout ⇒ String
Get stdout of all commands.
-
#clear ⇒ Object
Clear list of known commands.
-
#find(cmd) {|Command| ... } ⇒ Object
Find command.
- #get_process(wanted) ⇒ Object deprecated Deprecated.
-
#initialize(opts = {}) ⇒ CommandMonitor
constructor
A new instance of CommandMonitor.
- #last_exit_status ⇒ Object deprecated Deprecated.
- #only_processes ⇒ Object deprecated Deprecated.
- #output_from(cmd) ⇒ Object deprecated Deprecated.
-
#register_command(cmd) ⇒ Object
Register command to monitor.
- #stderr_from(cmd) ⇒ Object deprecated Deprecated.
- #stdout_from(cmd) ⇒ Object deprecated Deprecated.
- #stop_process(process) ⇒ Object deprecated Deprecated.
- #stop_processes! ⇒ Object deprecated Deprecated.
- #terminate_process!(process) ⇒ Object deprecated Deprecated.
- #terminate_processes ⇒ Object deprecated Deprecated.
Constructor Details
#initialize(opts = {}) ⇒ CommandMonitor
Returns a new instance of CommandMonitor.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aruba/platforms/command_monitor.rb', line 37 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. end |
Instance Attribute Details
#last_command_started ⇒ Object
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_stopped ⇒ Object
Return the last command stopped
50 51 52 53 54 55 56 |
# File 'lib/aruba/platforms/command_monitor.rb', line 50 def last_command_stopped return @last_command_stopped unless @last_command_stopped.nil? registered_commands.each(&:stop) @last_command_stopped end |
#registered_commands ⇒ Object (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_output ⇒ String
Get stderr and stdout of all commands
160 161 162 |
# File 'lib/aruba/platforms/command_monitor.rb', line 160 def all_output all_stdout << all_stderr end |
#all_stderr ⇒ String
Get stderr of all commands
146 147 148 149 150 151 152 153 154 |
# File 'lib/aruba/platforms/command_monitor.rb', line 146 def all_stderr registered_commands.each(&:stop) if RUBY_VERSION < '1.9.3' registered_commands.inject("") { |a, e| a << e.stderr; a } else registered_commands.each_with_object("") { |e, a| a << e.stderr } end end |
#all_stdout ⇒ String
Get stdout of all commands
132 133 134 135 136 137 138 139 140 |
# File 'lib/aruba/platforms/command_monitor.rb', line 132 def all_stdout registered_commands.each(&:stop) if RUBY_VERSION < '1.9.3' registered_commands.inject("") { |a, e| a << e.stdout; a } else registered_commands.each_with_object("") { |e, a| a << e.stdout } end end |
#clear ⇒ Object
Clear list of known commands
91 92 93 94 95 96 |
# File 'lib/aruba/platforms/command_monitor.rb', line 91 def clear registered_commands.each(&:terminate) registered_commands.clear self end |
#find(cmd) {|Command| ... } ⇒ Object
Find command
81 82 83 84 85 86 87 88 |
# File 'lib/aruba/platforms/command_monitor.rb', line 81 def find(cmd) cmd = cmd.commandline if cmd.respond_to? :commandline command = registered_commands.reverse.find { |c| c.commandline == cmd } fail CommandNotFoundError, "No command named '#{cmd}' has been started" if command.nil? command end |
#get_process(wanted) ⇒ Object
207 208 209 210 211 212 |
# File 'lib/aruba/platforms/command_monitor.rb', line 207 def get_process(wanted) command = find(wanted) raise ArgumentError.new("No process named '#{wanted}' has been started") unless command command end |
#last_exit_status ⇒ Object
165 166 167 168 169 170 171 |
# File 'lib/aruba/platforms/command_monitor.rb', line 165 def last_exit_status Aruba.platform.deprecated('The use of "#last_exit_status" is deprecated. Use "last_command_(started|stopped).exit_status" instead') return @last_exit_status if @last_exit_status registered_commands.each(&:stop) @last_exit_status end |
#only_processes ⇒ Object
200 201 202 203 204 |
# File 'lib/aruba/platforms/command_monitor.rb', line 200 def only_processes Aruba.platform.deprecated('The use of "#only_processes" is deprecated.') registered_commands end |
#output_from(cmd) ⇒ Object
Fetch output (stdout, stderr) from command
103 104 105 106 |
# File 'lib/aruba/platforms/command_monitor.rb', line 103 def output_from(cmd) cmd = Utils.detect_ruby(cmd) find(cmd).output end |
#register_command(cmd) ⇒ Object
Register command to monitor
215 216 217 218 219 |
# File 'lib/aruba/platforms/command_monitor.rb', line 215 def register_command(cmd) registered_commands << cmd self end |
#stderr_from(cmd) ⇒ Object
Fetch stderr from command
123 124 125 126 |
# File 'lib/aruba/platforms/command_monitor.rb', line 123 def stderr_from(cmd) cmd = Utils.detect_ruby(cmd) find(cmd).stderr end |
#stdout_from(cmd) ⇒ Object
Fetch stdout from command
113 114 115 116 |
# File 'lib/aruba/platforms/command_monitor.rb', line 113 def stdout_from(cmd) cmd = Utils.detect_ruby(cmd) find(cmd).stdout end |
#stop_process(process) ⇒ Object
174 175 176 177 |
# File 'lib/aruba/platforms/command_monitor.rb', line 174 def stop_process(process) @last_command_stopped = process @last_exit_status = process.stop(announcer) end |
#stop_processes! ⇒ Object
185 186 187 188 189 |
# File 'lib/aruba/platforms/command_monitor.rb', line 185 def stop_processes! Aruba.platform.deprecated('The use of "#stop_processes!" is deprecated.') registered_commands.each(&:stop) end |
#terminate_process!(process) ⇒ Object
180 181 182 |
# File 'lib/aruba/platforms/command_monitor.rb', line 180 def terminate_process!(process) process.terminate end |
#terminate_processes ⇒ Object
Terminate all running processes
193 194 195 196 197 |
# File 'lib/aruba/platforms/command_monitor.rb', line 193 def terminate_processes Aruba.platform.deprecated('The use of "#terminate_processes" is deprecated.') registered_commands.each(&:terminate) end |