Class: Riml::BacktraceFilter

Inherits:
Object
  • Object
show all
Includes:
Environment
Defined in:
lib/riml/backtrace_filter.rb

Constant Summary collapse

RIML_INTERNAL_FILE_REGEX =
/#{ROOTDIR}/

Constants included from Environment

Environment::BINDIR, Environment::LIBDIR, Environment::ROOTDIR

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error) ⇒ BacktraceFilter

Returns a new instance of BacktraceFilter.



11
12
13
# File 'lib/riml/backtrace_filter.rb', line 11

def initialize(error)
  @error = error
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



9
10
11
# File 'lib/riml/backtrace_filter.rb', line 9

def error
  @error
end

Instance Method Details

#filter!(first_i = 0, last_i = -1)) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/riml/backtrace_filter.rb', line 15

def filter!(first_i = 0, last_i = -1)
  if first_i < 0
    raise ArgumentError, "first argument must be >= 0"
  end
  if last_i > 0 && first_i > last_i
    raise ArgumentError, "first index must come before (or be equal to) last index"
  end

  # check if `responds_to?(:debug)` because we don't want to have to
  # require 'riml.rb' just for this
  unless Riml.respond_to?(:debug) && Riml.debug
    add_to_head = @error.backtrace[0...first_i] || []
    add_to_tail = @error.backtrace[last_i...-1] || []
    backtrace = @error.backtrace[first_i..last_i] || []
    backtrace.delete_if { |loc| RIML_INTERNAL_FILE_REGEX =~ loc }
    @error.set_backtrace(add_to_head + backtrace + add_to_tail)
  end
end