Sha256: f51f74417ac008b119866045265c111f153ee326a4e6f028a72eea73feb33133

Contents?: true

Size: 1.6 KB

Versions: 16

Compression:

Stored size: 1.6 KB

Contents

require 'simplabs/excellent/extensions/string'

module Simplabs

  module Excellent

    # 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 <tt>{{token}}</tt> that
    # correspond to the valeus in the +info+ hash, e.g.:
    #
    #  '{{method}} has abc score of {{score}}.'
    #  { :method => 'User#full_name', :score => 10 }
    class Warning

      # The check that produced the warning
      attr_reader :check

      # The name of the file the check found the problematic code in
      attr_reader :filename

      # The file number where the check found the problematic code
      attr_reader :line_number

      # The warning message
      attr_reader :message

      # Additional info for the warning (see above)
      attr_reader :info

      # The template used to produce the warning (see above)
      attr_reader :message_template

      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

    end

  end

end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
simplabs-excellent-1.2.1 lib/simplabs/excellent/warning.rb
simplabs-excellent-1.2.2 lib/simplabs/excellent/warning.rb
simplabs-excellent-1.3.0 lib/simplabs/excellent/warning.rb
simplabs-excellent-1.3.1 lib/simplabs/excellent/warning.rb
simplabs-excellent-1.4.0 lib/simplabs/excellent/warning.rb
simplabs-excellent-1.4.1 lib/simplabs/excellent/warning.rb
simplabs-excellent-1.4.2 lib/simplabs/excellent/warning.rb
simplabs-excellent-1.5.0 lib/simplabs/excellent/warning.rb
simplabs-excellent-1.5.1 lib/simplabs/excellent/warning.rb
simplabs-excellent-1.5.2 lib/simplabs/excellent/warning.rb
simplabs-excellent-1.5.3 lib/simplabs/excellent/warning.rb
excellent-1.7.2 lib/simplabs/excellent/warning.rb
excellent-1.7.1 lib/simplabs/excellent/warning.rb
excellent-1.7.0 lib/simplabs/excellent/warning.rb
excellent-1.6.0 lib/simplabs/excellent/warning.rb
excellent-1.5.4 lib/simplabs/excellent/warning.rb