Class: Brakeman::Warning
- Inherits:
-
Object
- Object
- Brakeman::Warning
- Defined in:
- lib/brakeman/warning.rb
Overview
The Warning class stores information about warnings
Instance Attribute Summary (collapse)
-
- (Object) called_from
readonly
Returns the value of attribute called_from.
-
- (Object) check
readonly
Returns the value of attribute check.
-
- (Object) class
readonly
Returns the value of attribute class.
-
- (Object) code
Returns the value of attribute code.
-
- (Object) confidence
readonly
Returns the value of attribute confidence.
-
- (Object) context
Returns the value of attribute context.
-
- (Object) controller
readonly
Returns the value of attribute controller.
-
- (Object) file
Returns the value of attribute file.
-
- (Object) line
readonly
Returns the value of attribute line.
-
- (Object) message
Returns the value of attribute message.
-
- (Object) method
readonly
Returns the value of attribute method.
-
- (Object) model
readonly
Returns the value of attribute model.
-
- (Object) template
readonly
Returns the value of attribute template.
-
- (Object) warning_set
readonly
Returns the value of attribute warning_set.
-
- (Object) warning_type
readonly
Returns the value of attribute warning_type.
Instance Method Summary (collapse)
- - (Boolean) eql?(other_warning)
-
- (Object) format_code
Return String of the code output from the OutputProcessor and stripped of newlines and tabs.
-
- (Object) format_message
Return formatted warning message.
- - (Object) hash
-
- (Warning) initialize(options = {})
constructor
options can be a result from Tracker#find_call.
-
- (Object) to_row(type = :warning)
Generates a hash suitable for inserting into a Ruport table.
-
- (Object) view_name
Returns name of a view, including where it was rendered from.
Constructor Details
- (Warning) initialize(options = {})
options can be a result from Tracker#find_call. Otherwise, it can be nil.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/brakeman/warning.rb', line 9 def initialize = {} @view_name = nil [:called_from, :check, :class, :code, :confidence, :controller, :file, :line, :message, :method, :model, :template, :warning_set, :warning_type].each do |option| self.instance_variable_set("@#{option}", [option]) end result = [:result] if result if result[:location][0] == :template #template result @template ||= result[:location][1] @code ||= result[:call] else @class ||= result[:location][1] @method ||= result[:location][2] @code ||= result[:call] end end if @code and not @line and @code.respond_to? :line @line = @code.line end unless @warning_set if self.model @warning_set = :model elsif self.template @warning_set = :template @called_from = self.template[:caller] elsif self.controller @warning_set = :controller else @warning_set = :warning end end @format_message = nil @row = nil end |
Instance Attribute Details
- (Object) called_from (readonly)
Returns the value of attribute called_from
3 4 5 |
# File 'lib/brakeman/warning.rb', line 3 def called_from @called_from end |
- (Object) check (readonly)
Returns the value of attribute check
3 4 5 |
# File 'lib/brakeman/warning.rb', line 3 def check @check end |
- (Object) class (readonly)
Returns the value of attribute class
3 4 5 |
# File 'lib/brakeman/warning.rb', line 3 def class @class end |
- (Object) code
Returns the value of attribute code
6 7 8 |
# File 'lib/brakeman/warning.rb', line 6 def code @code end |
- (Object) confidence (readonly)
Returns the value of attribute confidence
3 4 5 |
# File 'lib/brakeman/warning.rb', line 3 def confidence @confidence end |
- (Object) context
Returns the value of attribute context
6 7 8 |
# File 'lib/brakeman/warning.rb', line 6 def context @context end |
- (Object) controller (readonly)
Returns the value of attribute controller
3 4 5 |
# File 'lib/brakeman/warning.rb', line 3 def controller @controller end |
- (Object) file
Returns the value of attribute file
6 7 8 |
# File 'lib/brakeman/warning.rb', line 6 def file @file end |
- (Object) line (readonly)
Returns the value of attribute line
3 4 5 |
# File 'lib/brakeman/warning.rb', line 3 def line @line end |
- (Object) message
Returns the value of attribute message
6 7 8 |
# File 'lib/brakeman/warning.rb', line 6 def @message end |
- (Object) method (readonly)
Returns the value of attribute method
3 4 5 |
# File 'lib/brakeman/warning.rb', line 3 def method @method end |
- (Object) model (readonly)
Returns the value of attribute model
3 4 5 |
# File 'lib/brakeman/warning.rb', line 3 def model @model end |
- (Object) template (readonly)
Returns the value of attribute template
3 4 5 |
# File 'lib/brakeman/warning.rb', line 3 def template @template end |
- (Object) warning_set (readonly)
Returns the value of attribute warning_set
3 4 5 |
# File 'lib/brakeman/warning.rb', line 3 def warning_set @warning_set end |
- (Object) warning_type (readonly)
Returns the value of attribute warning_type
3 4 5 |
# File 'lib/brakeman/warning.rb', line 3 def warning_type @warning_type end |
Instance Method Details
- (Boolean) eql?(other_warning)
55 56 57 |
# File 'lib/brakeman/warning.rb', line 55 def eql? other_warning self.hash == other_warning.hash end |
- (Object) format_code
Return String of the code output from the OutputProcessor and stripped of newlines and tabs.
71 72 73 |
# File 'lib/brakeman/warning.rb', line 71 def format_code Brakeman::OutputProcessor.new.format(self.code).gsub(/(\t|\r|\n)+/, " ") end |
- (Object) format_message
Return formatted warning message
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/brakeman/warning.rb', line 76 def return @format_message if @format_message @format_message = self..dup if self.line @format_message << " near line #{self.line}" end if self.code @format_message << ": #{format_code}" end @format_message end |
- (Object) hash
51 52 53 |
# File 'lib/brakeman/warning.rb', line 51 def hash self..hash end |
- (Object) to_row(type = :warning)
Generates a hash suitable for inserting into a Ruport table
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/brakeman/warning.rb', line 93 def to_row type = :warning return @row if @row @row = { "Confidence" => self.confidence, "Warning Type" => self.warning_type.to_s, "Message" => self. } case type when :template @row["Template"] = self.view_name.to_s when :model @row["Model"] = self.model.to_s when :controller @row["Controller"] = self.controller.to_s when :warning @row["Class"] = self.class.to_s @row["Method"] = self.method.to_s end @row end |
- (Object) view_name
Returns name of a view, including where it was rendered from
60 61 62 63 64 65 66 67 |
# File 'lib/brakeman/warning.rb', line 60 def view_name return @view_name if @view_name if called_from @view_name = "#{template[:name]} (#{called_from})" else @view_name = template[:name] end end |