lib/backtrace.rb in backtrace-0.2.0 vs lib/backtrace.rb in backtrace-0.3.0

- old
+ new

@@ -25,30 +25,31 @@ # Backtrace as a string. # Author:: Yegor Bugayenko (yegor256@gmail.com) # Copyright:: Copyright (c) 2018 Yegor Bugayenko # License:: MIT class Backtrace - def initialize(exp, stop: '') + def initialize(exp, mine: '') @exp = exp - @stop = stop + @mine = (mine.is_a?(Regexp) ? mine : Regexp.new(Regexp.quote(mine))) end def to_s [ @exp.class.name, ': ', @exp.message, "\n\t", - @exp.backtrace.reverse.drop_while { |t| !t.include?(@stop) } + @exp.backtrace.reverse + .drop_while { |t| @mine.match(t).nil? } .reverse.join("\n\t") ].join end - def self.exec(swallow: false, log: nil) + def self.exec(swallow: false, log: nil, mine: '') yield rescue StandardError => e - trace = Backtrace.new(e).to_s - if log.nil? + trace = Backtrace.new(e, mine: mine).to_s + if log.nil? || !log.respond_to?(:error) puts trace else log.error(trace) end raise e unless swallow