Class: RaLoSe::Command
- Inherits:
-
Object
- Object
- RaLoSe::Command
- Defined in:
- lib/ralose/command.rb
Constant Summary collapse
- RED =
"\e[31m".freeze
- RESET_COLOR =
"\e[0m".freeze
- REQUEST_ID_RE =
- a9c56d04-d706-49ae-b0a2-e7636c650d5e
/\[[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\]/.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Command
constructor
A new instance of Command.
- #run! ⇒ Object
Constructor Details
#initialize ⇒ Command
Returns a new instance of Command.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ralose/command.rb', line 12 def initialize @colorized_output = true @case_insensitive = false @current_request_id = nil @current_request_lines = [] @print_current_request = false @query = Regexp.new(ARGV.shift, @case_insensitive) end |
Class Method Details
.run! ⇒ Object
25 26 27 |
# File 'lib/ralose/command.rb', line 25 def self.run! new.run! end |
Instance Method Details
#run! ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ralose/command.rb', line 29 def run! # Pipe handling based on: https://www.jstorimer.com/blogs/workingwithcode/7766125-writing-ruby-scripts-that-respect-pipelines # Read from file passed in ARGV, or STDIN. ARGF.each_line do |line| request_id = line[REQUEST_ID_RE] if request_id.nil? next end if request_id != @current_request_id print_current_request new_request(request_id) end if line.match?(@query) @print_current_request = true if @colorized_output line.gsub!(@query, "#{RED}\\0#{RESET_COLOR}") end end @current_request_lines << line end print_current_request end |