class Autoreporter
Attributes
commands[RW]
delay[RW]
verbose[RW]
Public Class Methods
new()
click to toggle source
# File lib/autoreporter.rb, line 8 def initialize @output = nil @delay = 60 @verbose = false @commands = [] end
Public Instance Methods
call()
click to toggle source
# File lib/autoreporter.rb, line 47 def call while true run_commands! display_result! wait_for_condition! end end
clear_terminal!()
click to toggle source
# File lib/autoreporter.rb, line 26 def clear_terminal! # system("clear") doesn't clear scrollback buffer on iTerm2, we need to do this: print "\e[H\e[J\e[3J" end
display_result!()
click to toggle source
# File lib/autoreporter.rb, line 31 def display_result! clear_terminal! puts *@output end
run_command(cmd)
click to toggle source
# File lib/autoreporter.rb, line 15 def run_command(cmd) output, status = Open3.capture2e(cmd) output += "\n" if output != "" and output[-1] != "\n" output = "Running: #{cmd}\n" + output if verbose output end
run_commands!()
click to toggle source
# File lib/autoreporter.rb, line 22 def run_commands! @output = @commands.map{|cmd| run_command(cmd)} end
wait_for_condition!()
click to toggle source
Wait for either @delay seconds or for user forcing autorefresh by pressing enter
# File lib/autoreporter.rb, line 38 def wait_for_condition! begin Timeout.timeout(@delay) do STDIN.readline end rescue Timeout::Error end end