class RequestLogAnalyzer::LineDefinition

The line definition class is used to specify what lines should be parsed from the log file. It contains functionality to match a line against the definition and parse the information from this line. This is used by the LogParser class when parsing a log file..

Attributes

captures[RW]
compound[RW]
header[RW]
header?[RW]
name[R]
regexp[RW]
teaser[RW]

Public Class Methods

define(name) { |definition| ... } click to toggle source
   # File lib/request_log_analyzer/line_definition.rb
60 def self.define(name, &_block)
61   definition = new(name)
62   yield(definition) if block_given?
63   definition
64 end
new(name, definition = {}) click to toggle source

Initializes the LineDefinition instance with a hash containing the different elements of the definition.

   # File lib/request_log_analyzer/line_definition.rb
52 def initialize(name, definition = {})
53   @name     = name
54   @captures = []
55   @teaser   = nil
56   @compound = []
57   definition.each { |key, value| send("#{key}=".to_sym, value) }
58 end

Public Instance Methods

=~(line, &warning_handler)
Alias for: matches
all_captured_variables() click to toggle source
   # File lib/request_log_analyzer/line_definition.rb
74 def all_captured_variables
75   captures.map { |c| c[:name] } + captures.map { |c| c[:provides] }.compact.map { |pr| pr.keys }.flatten
76 end
capture(name) click to toggle source
   # File lib/request_log_analyzer/line_definition.rb
66 def capture(name)
67   new_capture_hash = {}
68   new_capture_hash[:name] = name
69   new_capture_hash[:type] = :string
70   captures << new_capture_hash
71   CaptureDefiner.new(new_capture_hash)
72 end
captures?(name) click to toggle source

Returns true if this line captures values of the given name

    # File lib/request_log_analyzer/line_definition.rb
134 def captures?(name)
135   all_captured_variables.include?(name)
136 end
convert_captured_values(values, request) click to toggle source

Updates a captures hash using the converters specified in the request and handle the :provides option in the line definition.

    # File lib/request_log_analyzer/line_definition.rb
114 def convert_captured_values(values, request)
115   value_hash = {}
116   captures.each_with_index do |capture, index|
117 
118     # convert the value using the request convert_value function
119     converted = request.convert_value(values[index], capture)
120     value_hash[capture[:name]] ||= converted
121 
122     # Add items directly to the resulting hash from the converted value
123     # if it is a hash and they are set in the :provides hash for this line definition
124     if converted.is_a?(Hash) && capture[:provides].is_a?(Hash)
125       capture[:provides].each do |name, type|
126         value_hash[name] ||= request.convert_value(converted[name],  type: type)
127       end
128     end
129   end
130   value_hash
131 end
match_for(line, request, &warning_handler) click to toggle source

matches the line and converts the captured values using the request’s convert_value function.

    # File lib/request_log_analyzer/line_definition.rb
104 def match_for(line, request, &warning_handler)
105   if match_info = matches(line, &warning_handler)
106     convert_captured_values(match_info[:captures], request)
107   else
108     false
109   end
110 end
matches(line, &warning_handler) click to toggle source

Checks whether a given line matches this definition. It will return false if a line does not match. If the line matches, a hash is returned with all the fields parsed from that line as content. If the line definition has a teaser-check, a :teaser_check_failed warning will be emitted if this teaser-check is passed, but the full regular exprssion does not ,atch.

   # File lib/request_log_analyzer/line_definition.rb
83 def matches(line, &warning_handler)
84   if @teaser.nil? || @teaser =~ line
85     if match_data = line.match(@regexp)
86       return { line_definition: self, captures: match_data.captures }
87     else
88       if @teaser && warning_handler
89         warning_handler.call(:teaser_check_failed, "Teaser matched for #{name.inspect}, but full line did not:\n#{line.inspect}")
90       end
91       return false
92     end
93   else
94     return false
95   end
96 rescue
97   return false
98 end
Also aliased as: =~