class ActionCommand::PrettyPrintLogAction

Action that parses a log and pretty prints the log, optionally filtering on a particular command sequence.

Attributes

dest[RW]
sequence[RW]
source[RW]

Public Class Methods

describe_io() click to toggle source

specifies the input/output for this command

# File lib/action_command/pretty_print_log_action.rb, line 10
def self.describe_io
  return ActionCommand.describe_io(self, 'Command that does some logging') do |io|
    io.input(:source, 'Stream to read')
    io.input(:sequence, 'sequence to filter on', OPTIONAL)
    io.input(:dest, 'Optional output stream, defaults to STDOUT', OPTIONAL)
  end
end

Protected Instance Methods

execute_internal(_result) click to toggle source

Say hello to the specified person.

# File lib/action_command/pretty_print_log_action.rb, line 28
def execute_internal(_result)
  item = LogMessage.new
  parser = LogParser.new(@source, @sequence)
  sequences = {}
  # keep track of sequences, and when you complete one, then print out the
  # entire thing at once.
  while parser.next(item)
    if item.kind?(ActionCommand::LOG_KIND_COMMAND_OUTPUT) && item.root?
      process_output(sequences, item)
    else
      process_other(sequences, item)
    end  
    item = LogMessage.new
  end
    
  # print out any incomplete sequences
  print_sequences(sequences)
end
print_cmd_input(item) click to toggle source
print_cmd_output(item) click to toggle source
print_msg(depth, item) click to toggle source
print_sequence(sequence) click to toggle source
print_sequence_item(item) click to toggle source
print_sequences(sequences) click to toggle source
println(depth, line) click to toggle source
# File lib/action_command/pretty_print_log_action.rb, line 106
def println(depth, line)
  padding = ''.rjust(depth * 2)
  dest.puts("#{padding}#{line}")
end
process_other(sequences, item) click to toggle source
# File lib/action_command/pretty_print_log_action.rb, line 47
def process_other(sequences, item)
  sequences[item.sequence] = [] unless sequences.key?(item.sequence)
  sequences[item.sequence] << item
end
process_output(sequences, item) click to toggle source
# File lib/action_command/pretty_print_log_action.rb, line 52
def process_output(sequences, item)
  seq = sequences[item.sequence]
  sequences.delete(item.sequence)
  seq << item
  print_sequence(seq)
end