Class: Spackle::Output::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/spackle/output/base.rb

Overview

This is the foundation of all Spackle::Output classes, but by itself it does nothing.

Using an Output class should be simple: (assuming errors is an Array of Spackle::Error objects) puts Spackle::Output::VimQuickfix.format(errors)

The child class (VimQuickfix) only needs to implement the format_backtrace instance method.

Spackle::Output::Base is responsible for things like:

  • iterating over the backtrace collection

  • making pathnames relative

  • limiting the number of errors that are output

  • filtering the backtrace output by filename

Spackle::Output::Base interacts with Spackle’s Configuration

If you’re writing your own Output class, it should be quite easy to override some of the Configuration handling if your class requires it.

Direct Known Subclasses

VimQuickfix

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error = nil) ⇒ Base

Returns a new instance of Base.



26
27
28
# File 'lib/spackle/output/base.rb', line 26

def initialize(error = nil)
  self.error = error || Spackle.current_error
end

Instance Attribute Details

#errorObject

Returns the value of attribute error.



25
26
27
# File 'lib/spackle/output/base.rb', line 25

def error
  @error
end

Class Method Details

.format(error = nil) ⇒ Object



40
41
42
# File 'lib/spackle/output/base.rb', line 40

def self.format(error = nil)
  new(error || Spackle.current_error).format
end

Instance Method Details

#formatObject



36
37
38
# File 'lib/spackle/output/base.rb', line 36

def format    
  formatted_lines.join("\n") + "\n"
end

#formatted_linesObject



30
31
32
33
34
# File 'lib/spackle/output/base.rb', line 30

def formatted_lines
  error.backtrace.map do |bt|
    format_backtrace_line error.message, bt.file, bt.line
  end
end