Class: Beaver::Request
- Inherits:
-
Object
- Object
- Beaver::Request
- 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
Constant Summary collapse
- BLANK_STR =
:nodoc:
''
- BLANK_HASH =
:nodoc:
{}
Class Method Summary collapse
-
.for(line) ⇒ Object
Returns a new Request object for the given log line, or nil if one cannot be found.
-
.inherited(klass) ⇒ Object
Add a child Request parser.
-
.match?(line) ⇒ Boolean
Returns true if the given line look like a request of this class.
Instance Method Summary collapse
-
#<<(line) ⇒ Object
Append a log line.
-
#completed? ⇒ Boolean
Returns true if the request has all the information it needs to be properly parsed.
-
#date ⇒ Object
Returns the date on which the request was made.
-
#final! ⇒ Object
When called inside of a Beaver::Dam#hit block, this Request will not match against any other Beaver::Dam.
-
#final? ⇒ Boolean
Returns true if this Request should not be matched against any more Dams.
-
#initialize(data = nil) ⇒ Request
constructor
Accepts a String of log data, presumably ones which belong to a single request.
-
#invalid? ⇒ Boolean
Returns true if this request has become invalid during reconstitution.
-
#ip ⇒ Object
Returns the IP address of the request.
-
#method ⇒ Object
Returns the request method.
-
#params ⇒ Object
Returns the request parameters as a Hash (this is more expensive than Request#params_str).
-
#params_str ⇒ Object
Returns the request parameters as a String.
-
#path ⇒ Object
Returns the request path.
-
#skip! ⇒ Object
When called inside of a Beaver::Dam#hit block, this Request will not be matched.
-
#status ⇒ Object
Returns the response status.
-
#time ⇒ Object
Returns the time at which the request was made.
-
#to_s ⇒ Object
Returns the log data that make up this Request.
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
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
103 |
# File 'lib/beaver/request.rb', line 103 def completed?; true; end |
#date ⇒ Object
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.
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
100 |
# File 'lib/beaver/request.rb', line 100 def invalid?; false; end |
#ip ⇒ Object
Returns the IP address of the request
70 71 72 |
# File 'lib/beaver/request.rb', line 70 def ip @ip ||= parse_ip end |
#method ⇒ Object
Returns the request method
50 51 52 |
# File 'lib/beaver/request.rb', line 50 def method @method ||= parse_method end |
#params ⇒ Object
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_str ⇒ Object
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 |
#path ⇒ Object
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 |
#status ⇒ Object
Returns the response status
55 56 57 |
# File 'lib/beaver/request.rb', line 55 def status @status ||= parse_status end |
#time ⇒ Object
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_s ⇒ Object
Returns the log data that make up this Request.
37 |
# File 'lib/beaver/request.rb', line 37 def to_s; @data; end |