Module: Tomo::Configuration::DSL::ErrorFormatter

Includes:
Tomo::Colors
Defined in:
lib/tomo/configuration/dsl/error_formatter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Tomo::Colors

enabled?

Instance Attribute Details

#dsl_linesObject

Returns the value of attribute dsl_lines.



31
32
33
# File 'lib/tomo/configuration/dsl/error_formatter.rb', line 31

def dsl_lines
  @dsl_lines
end

#dsl_pathObject

Returns the value of attribute dsl_path.



31
32
33
# File 'lib/tomo/configuration/dsl/error_formatter.rb', line 31

def dsl_path
  @dsl_path
end

#error_line_noObject

Returns the value of attribute error_line_no.



31
32
33
# File 'lib/tomo/configuration/dsl/error_formatter.rb', line 31

def error_line_no
  @error_line_no
end

Class Method Details

.decorate(error, path, lines) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/tomo/configuration/dsl/error_formatter.rb', line 8

def decorate(error, path, lines)
  line_no = find_line_no(path, error.message, *error.backtrace[0..1])
  return error if line_no.nil?

  error.extend(self)
  error.dsl_lines = lines || []
  error.dsl_path = path
  error.error_line_no = line_no
  error
end

Instance Method Details

#to_consoleObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/tomo/configuration/dsl/error_formatter.rb', line 33

def to_console
  <<~ERROR
    Configuration syntax error in #{yellow(dsl_path)} at line #{yellow(error_line_no)}.

    #{highlighted_lines}
    #{Colors.red([self.class, message].join(': '))}

    Visit #{Colors.blue('https://tomo.mattbrictson.com/configuration')} for syntax reference.
    #{trace_hint}
  ERROR
end