class Blufin::ScannerError
Constants
- CODE_COLOR
- ERROR_COLOR
- HEADER_COLOR
- LINE_COLOR
Attributes
error_type[RW]
file[RW]
line[RW]
line_number[RW]
message[RW]
Public Class Methods
add_error(file, message, line = nil, line_number = nil)
click to toggle source
Add an error. @return Object
# File lib/scan/scanner_error.rb, line 80 def self.add_error(file, message, line = nil, line_number = nil) Blufin::ScannerError.new(file, line, line_number, message) end
highlight_filename(file)
click to toggle source
Takes a file like '/Users/Albert/Repos/eworldes/fmm/client/src/js/app/overlays.js' and highlights 'overlays.js' @return string
# File lib/scan/scanner_error.rb, line 69 def self.highlight_filename(file) raise RuntimeError, "Expected String, instead got: #{file.class}" unless file.is_a?(String) fs = file.split('/') fl = fs.pop is_file = fl =~ /\./ color = is_file ? 202 : 75 "\x1B[48;5;233m \x1B[38;5;240m#{fs.join('/')}/\x1B[38;5;#{color}m#{fl} \x1B[0m#{is_file ? nil : '(path)'}" end
new(file, line, line_number, message)
click to toggle source
Initialize a ScannerError
object. @return void
# File lib/scan/scanner_error.rb, line 16 def initialize(file, line, line_number, message) raise RuntimeError, "File does not exist: #{file}" unless Blufin::Files::file_exists(file) unless file.nil? raise RuntimeError, "Line number must be positive integer, got: #{line_number}" if !line_number.nil? && line_number.to_s !~ /^\d+$/ raise RuntimeError, 'Message cannot be nil or blank.' if message.nil? || message.strip == '' self.file = file.nil? ? "\xe2\x80\x94" : file self.line = line.nil? ? "\xe2\x80\x94" : line self.line_number = line_number.nil? ? "\xe2\x80\x94" : line_number.to_s self.message = message end
output_cli(errors, clear_screen = true)
click to toggle source
Static method to output the errors to Terminal
. @return void
# File lib/scan/scanner_error.rb, line 28 def self.output_cli(errors, clear_screen = true) raise RuntimeError, "Expected Array, instead got: #{errors.class}" unless errors.is_a?(Array) return unless errors.any? system('clear') if clear_screen puts if clear_screen @files = {} errors.each do |error| file = error.file @files[file] = [] unless @files.has_key?(file) @files[file] << error end @files.each do |file, inner_errors| puts " #{highlight_filename(file)}" table(:border => false) do wildcard_width = Blufin::Terminal::get_terminal_width - 120 wildcard_width = 1 if wildcard_width < 0 message_width = 100 row do column('', :width => 2, :color => HEADER_COLOR) column('-' * 5, :width => 5, :color => HEADER_COLOR) column('-' * message_width, :width => message_width, :color => HEADER_COLOR) column('-' * wildcard_width, :width => wildcard_width, :color => HEADER_COLOR) column('', :width => 2, :color => HEADER_COLOR) end inner_errors.each do |error| row do column('') column(error.line_number[0..5].ljust(5, ' '), :color => LINE_COLOR) column(error.message[0..message_width], :color => ERROR_COLOR) column(error.line.strip[0..wildcard_width], :color => CODE_COLOR) column('') end end end puts end exit 1 end