Class: Backtrace
- Inherits:
-
Object
- Object
- Backtrace
- Defined in:
- lib/backtrace.rb
Overview
Backtrace as a string.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2018 Yegor Bugayenko
- License
-
MIT
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(exp, mine: '') ⇒ Backtrace
constructor
A new instance of Backtrace.
- #to_s ⇒ Object
Constructor Details
#initialize(exp, mine: '') ⇒ Backtrace
Returns a new instance of Backtrace.
30 31 32 33 |
# File 'lib/backtrace.rb', line 30 def initialize(exp, mine: '') @exp = exp @mine = (mine.is_a?(Regexp) ? mine : Regexp.new(Regexp.quote(mine))) end |
Class Method Details
.exec(swallow: false, log: nil, mine: '') ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/backtrace.rb', line 47 def self.exec(swallow: false, log: nil, mine: '') yield rescue StandardError => e 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 end |
Instance Method Details
#to_s ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/backtrace.rb', line 35 def to_s [ @exp.class.name, ': ', @exp., "\n\t", @exp.backtrace.reverse .drop_while { |t| @mine.match(t).nil? } .reverse.join("\n\t") ].join end |