Class: Simplabs::Excellent::Warning

Inherits:
Object
  • Object
show all
Defined in:
lib/simplabs/excellent/warning.rb

Overview

The warnings returned by Excellent provide information about the file the possibly problematic code was found in as well as the line of the occurence, a warning message and a Hash with specific information about the warning.

Warnings also provide the message template that was used to generate the message. The message template contains tokens like {{token}} that correspond to the valeus in the info hash, e.g.:

'{{method}} has abc score of {{score}}.'
{ :method => 'User#full_name', :score => 10 }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(check, message, filename, line_number, info) ⇒ Warning

:nodoc:



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/simplabs/excellent/warning.rb', line 35

def initialize(check, message, filename, line_number, info) #:nodoc:
  @check       = check.to_s.underscore.to_sym
  @info        = info
  @filename    = filename
  @line_number = line_number.to_i

  @message = ''
  if !message.nil?
    @message_template = message
    @info.each { |key, value| message.gsub!(/\{\{#{key}\}\}/, value.to_s) }
    @message = message
  end
end

Instance Attribute Details

#checkObject (readonly)

The check that produced the warning



18
19
20
# File 'lib/simplabs/excellent/warning.rb', line 18

def check
  @check
end

#filenameObject (readonly)

The name of the file the check found the problematic code in



21
22
23
# File 'lib/simplabs/excellent/warning.rb', line 21

def filename
  @filename
end

#infoObject (readonly)

Additional info for the warning (see above)



30
31
32
# File 'lib/simplabs/excellent/warning.rb', line 30

def info
  @info
end

#line_numberObject (readonly)

The file number where the check found the problematic code



24
25
26
# File 'lib/simplabs/excellent/warning.rb', line 24

def line_number
  @line_number
end

#messageObject (readonly)

The warning message



27
28
29
# File 'lib/simplabs/excellent/warning.rb', line 27

def message
  @message
end

#message_templateObject (readonly)

The template used to produce the warning (see above)



33
34
35
# File 'lib/simplabs/excellent/warning.rb', line 33

def message_template
  @message_template
end