Class: TaintedLove::StackTrace
- Inherits:
-
Object
- Object
- TaintedLove::StackTrace
- Defined in:
- lib/tainted_love/stack_trace.rb
Constant Summary collapse
- BACKTRACE_LINE_REGEX =
/^((?:[a-zA-Z]:)?[^:]+):(\d+)(?::in `([^']+)')?$/.freeze
Instance Attribute Summary collapse
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#stack_trace ⇒ Object
Returns the value of attribute stack_trace.
Class Method Summary collapse
-
.current(skip = 2) ⇒ TaintedLove::StackTrace
Create a new StackTrace object from the current thread backtrace.
Instance Method Summary collapse
-
#initialize(stack_trace) ⇒ StackTrace
constructor
A new instance of StackTrace.
- #to_json ⇒ Object
-
#trace_hash ⇒ String
Produces a hash from the stack trace to identify identical code path.
Constructor Details
#initialize(stack_trace) ⇒ StackTrace
Returns a new instance of StackTrace.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/tainted_love/stack_trace.rb', line 9 def initialize(stack_trace) @stack_trace = stack_trace @lines = stack_trace.map do |line| next unless line.match(BACKTRACE_LINE_REGEX) { file: Regexp.last_match(1), line_number: Regexp.last_match(2).to_i, method: Regexp.last_match(3), } end.compact # Hack to remove TaintedLove.proxy_method @lines.shift if @lines.first[:file]['tainted_love/utils.rb'] end |
Instance Attribute Details
#lines ⇒ Object
Returns the value of attribute lines.
7 8 9 |
# File 'lib/tainted_love/stack_trace.rb', line 7 def lines @lines end |
#stack_trace ⇒ Object
Returns the value of attribute stack_trace.
7 8 9 |
# File 'lib/tainted_love/stack_trace.rb', line 7 def stack_trace @stack_trace end |
Class Method Details
.current(skip = 2) ⇒ TaintedLove::StackTrace
Create a new StackTrace object from the current thread backtrace
42 43 44 |
# File 'lib/tainted_love/stack_trace.rb', line 42 def self.current(skip = 2) new(Thread.current.backtrace(skip)) end |
Instance Method Details
#to_json ⇒ Object
32 33 34 35 36 |
# File 'lib/tainted_love/stack_trace.rb', line 32 def to_json { trace_hash: trace_hash, }.to_json end |
#trace_hash ⇒ String
Produces a hash from the stack trace to identify identical code path
27 28 29 30 |
# File 'lib/tainted_love/stack_trace.rb', line 27 def trace_hash lines = @lines.map { |line| "#{line[:file]}:#{line[:number]}" }.join(',') TaintedLove.hash(lines) end |