Class: Beaver::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/beaver/request.rb

Overview

Represents a single request from the logs. The base class for Beaver::Parsers::Rails and Beaver::Parsers::HTTP. Attributes common to both are defined here.

Direct Known Subclasses

Parsers::HTTP, Parsers::Rails

Constant Summary collapse

BLANK_STR =

:nodoc:

''
BLANK_HASH =

:nodoc:

{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = nil) ⇒ Request

Accepts a String of log data, presumably ones which belong to a single request.



31
32
33
34
# File 'lib/beaver/request.rb', line 31

def initialize(data=nil)
  @data = data || ''
  @final = false
end

Class Method Details

.for(line) ⇒ Object

Returns a new Request object for the given log line, or nil if one cannot be found.



20
21
22
23
# File 'lib/beaver/request.rb', line 20

def self.for(line)
  klass = @types.detect { |t| t.match? line }
  klass ? klass.new(line) : nil
end

.inherited(klass) ⇒ Object

Add a child Request parser



15
16
17
# File 'lib/beaver/request.rb', line 15

def self.inherited(klass)
  @types << klass
end

.match?(line) ⇒ Boolean

Returns true if the given line look like a request of this class

Returns:

  • (Boolean)


26
27
28
# File 'lib/beaver/request.rb', line 26

def self.match?(line)
  self::REGEX_MATCH =~ line rescue false
end

Instance Method Details

#<<(line) ⇒ Object

Append a log line



40
41
42
# File 'lib/beaver/request.rb', line 40

def <<(line)
  @data << line
end

#completed?Boolean

Returns true if the request has all the information it needs to be properly parsed

Returns:

  • (Boolean)


103
# File 'lib/beaver/request.rb', line 103

def completed?; true; end

#dateObject

Returns the date on which the request was made



75
76
77
# File 'lib/beaver/request.rb', line 75

def date
  @date ||= parse_date
end

#final!Object

When called inside of a Beaver::Dam#hit block, this Request will not match against any other Beaver::Dam.



90
91
92
# File 'lib/beaver/request.rb', line 90

def final!
  @final = true
end

#final?Boolean

Returns true if this Request should not be matched against any more Dams.

Returns:

  • (Boolean)


95
96
97
# File 'lib/beaver/request.rb', line 95

def final?
  @final
end

#invalid?Boolean

Returns true if this request has become invalid during reconstitution

Returns:

  • (Boolean)


100
# File 'lib/beaver/request.rb', line 100

def invalid?; false; end

#ipObject

Returns the IP address of the request



70
71
72
# File 'lib/beaver/request.rb', line 70

def ip
  @ip ||= parse_ip
end

#methodObject

Returns the request method



50
51
52
# File 'lib/beaver/request.rb', line 50

def method
  @method ||= parse_method
end

#paramsObject

Returns the request parameters as a Hash (this is more expensive than Request#params_str)



60
61
62
# File 'lib/beaver/request.rb', line 60

def params
  @params ||= parse_params
end

#params_strObject

Returns the request parameters as a String



65
66
67
# File 'lib/beaver/request.rb', line 65

def params_str
  @params_str ||= parse_params_str
end

#pathObject

Returns the request path



45
46
47
# File 'lib/beaver/request.rb', line 45

def path
  @path ||= parse_path
end

#skip!Object

When called inside of a Beaver::Dam#hit block, this Request will not be matched.



85
86
87
# File 'lib/beaver/request.rb', line 85

def skip!
  throw :skip
end

#statusObject

Returns the response status



55
56
57
# File 'lib/beaver/request.rb', line 55

def status
  @status ||= parse_status
end

#timeObject

Returns the time at which the request was made



80
81
82
# File 'lib/beaver/request.rb', line 80

def time
  @time ||= parse_time
end

#to_sObject

Returns the log data that make up this Request.



37
# File 'lib/beaver/request.rb', line 37

def to_s; @data; end