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(message, filename, line_number, info) ⇒ Warning

:nodoc:



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

def initialize(message, filename, line_number, info) #:nodoc:
  @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



16
17
18
# File 'lib/simplabs/excellent/warning.rb', line 16

def check
  @check
end

#filenameObject (readonly)

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



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

def filename
  @filename
end

#infoObject (readonly)

Additional info for the warning (see above)



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

def info
  @info
end

#line_numberObject (readonly)

The file number where the check found the problematic code



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

def line_number
  @line_number
end

#messageObject (readonly)

The warning message



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

def message
  @message
end

#message_templateObject (readonly)

The template used to produce the warning (see above)



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

def message_template
  @message_template
end