Class: LogErrorHandler::StdinReader

Inherits:
Object
  • Object
show all
Defined in:
lib/log_error_handler/stdin_reader.rb

Constant Summary collapse

TMP_DIR_NAME =
'log_error_handler'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tracker) ⇒ StdinReader

Returns a new instance of StdinReader.



5
6
7
# File 'lib/log_error_handler/stdin_reader.rb', line 5

def initialize(tracker)
  @tracker = tracker
end

Class Method Details

.start(tracker) ⇒ Object



9
10
11
12
13
# File 'lib/log_error_handler/stdin_reader.rb', line 9

def self.start(tracker)
  stdin_reader = new(tracker)
  stdin_reader.start
  stdin_reader
end

Instance Method Details

#startObject



15
16
17
18
19
20
21
22
23
# File 'lib/log_error_handler/stdin_reader.rb', line 15

def start
  Dir.mkdir("/tmp/#{TMP_DIR_NAME}") unless Dir.exist?("/tmp/#{TMP_DIR_NAME}")
  $stdout.puts 'Starting read input data...' if @tracker.options[:debug_mode]
  $stdin.each do |line|
    tid = line[@tracker.options[:tid_regexp]]
    @last_tid = tid || @last_tid
    write_to_file(line) if @last_tid
  end
end