class Lugg::Request
Request
is a value object representing a single log entry from start to finish. Its value is the original source text from the log file, but it defines various reader methods to extract useful information from it.
Note that a request is frozen once created. Two {Request} objects with the same source are considered equal.
@todo optimise performance
Attributes
hash[R]
source[R]
Public Class Methods
new(source)
click to toggle source
# File lib/lugg/request.rb, line 15 def initialize(source) @source = source @hash = self.class.hash ^ source.hash freeze end
Public Instance Methods
action()
click to toggle source
# File lib/lugg/request.rb, line 34 def action source[/^Processing by (\w+)#(\w+) as (\w+)$/, 1] + '#' + source[/^Processing by (\w+)#(\w+) as (\w+)$/, 2] end
code()
click to toggle source
# File lib/lugg/request.rb, line 47 def code source[/^Completed (\d+) (\w+)/, 1].to_i end
controller()
click to toggle source
# File lib/lugg/request.rb, line 30 def controller source[/^Processing by (\w+)#(\w+) as (\w+)$/, 1] end
duration()
click to toggle source
# File lib/lugg/request.rb, line 71 def duration source[/^Completed .* in (\d+)ms/, 1].to_i end
eql?(other)
click to toggle source
# File lib/lugg/request.rb, line 21 def eql?(other) self.class == other.class && source == other.source end
Also aliased as: ==
format()
click to toggle source
# File lib/lugg/request.rb, line 39 def format source[/^Processing by (\w+)#(\w+) as (\w+)$/, 3] end
ip()
click to toggle source
# File lib/lugg/request.rb, line 51 def ip source[/^Started .* for ([0-9\.]+)/, 1] end
method()
click to toggle source
# File lib/lugg/request.rb, line 26 def method source[/^Started ([A-Z]+)/, 1] end
params()
click to toggle source
# File lib/lugg/request.rb, line 75 def params params_string = source[/^ Parameters: (.+)$/, 1] String(params_string) .scan(/(?<!\\)"(.+?)(?<!\\)"=>(?<!\\)"(.+?)(?<!\\)"/) .each_with_object({}) do |match, output| output[match[0]] = match[1] end end
path()
click to toggle source
# File lib/lugg/request.rb, line 63 def path uri.split('?').first end
query()
click to toggle source
# File lib/lugg/request.rb, line 67 def query uri.split('?', 2).last end
status()
click to toggle source
# File lib/lugg/request.rb, line 43 def status source[/^Completed (\d+) (\w+)/, 2] end
timestamp()
click to toggle source
# File lib/lugg/request.rb, line 55 def timestamp Time.parse(source[/^Started .* at (.+)$/, 1]) end
uri()
click to toggle source
# File lib/lugg/request.rb, line 59 def uri source[/^Started \w+ "([^"]+)"/, 1] end