Module: ReplayLog

Defined in:
lib/replay_log.rb

Class Method Summary collapse

Class Method Details

.parse(input, match = '', sub = '', type = :nginx) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/replay_log.rb', line 2

def self.parse input, match='', sub='', type=:nginx
  result = ""
  if input.respond_to?(:each)
    input.each do |line|
      line_result = send("parse_line_#{type}".to_sym, line, match, sub)
      print line_result
      result << line_result
    end
  else
    result = send("parse_line_#{type}".to_sym, input, match, sub)
    print result
  end
  return result
end

.parse_line(line, match = '', sub = '') ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/replay_log.rb', line 25

def self.parse_line line, match='', sub=''
  request = line.split('"')[1]
  return if request.nil?

  uri = request.split[1]
  return if uri.nil?

  begin
    uri[match] = sub unless match.empty?
  rescue IndexError
    # simply output line that don't contain the 'replace' string
  ensure
    return uri.chomp + "\0"
  end
end

.parse_line_apache(line, match = '', sub = '') ⇒ Object



17
18
19
# File 'lib/replay_log.rb', line 17

def self.parse_line_apache line, match='', sub=''
  parse_line(line, match, sub)
end

.parse_line_nginx(line, match = '', sub = '') ⇒ Object



21
22
23
# File 'lib/replay_log.rb', line 21

def self.parse_line_nginx line, match='', sub=''
  parse_line(line, match, sub)
end