Class: KXI::Reflection::StackFrame
- Inherits:
-
Object
- Object
- KXI::Reflection::StackFrame
- Defined in:
- lib/kxi/reflection/stack_frame.rb
Overview
Represents frame of call stack
Class Method Summary collapse
-
.callstack(skip = 1) ⇒ Array<KXI::Reflection::StackFrame>
Parses callstack into array of StackFrame.
-
.from_backtrace(bt) ⇒ KXI::Reflection::StackFrame
Parses backtrace line into StackFrame.
Instance Method Summary collapse
-
#block? ⇒ Bool
Indicates whether frame is block.
-
#context ⇒ String
Returns the context of frame.
-
#file ⇒ String
Returns the file of frame.
-
#initialize(file, line, context = nil) ⇒ StackFrame
constructor
Instantiates the StackFrame class.
-
#line ⇒ Number
Returns the line number of frame.
-
#method ⇒ String?
Returns containing method of frame; nil if none.
-
#to_s ⇒ String
Converts class to string.
Constructor Details
#initialize(file, line, context = nil) ⇒ StackFrame
Instantiates the KXI::Reflection::StackFrame class
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/kxi/reflection/stack_frame.rb', line 43 def initialize(file, line, context = nil) @file = file @line = line @context = context if context == nil @block = nil else mt = /^block (\((?'levels'\d+) levels\) )?in (?'method'.+)$/mi.match(context) @block = mt == nil ? nil : mt['method'] end end |
Class Method Details
.callstack(skip = 1) ⇒ Array<KXI::Reflection::StackFrame>
Parses callstack into array of KXI::Reflection::StackFrame
64 65 66 67 68 69 70 |
# File 'lib/kxi/reflection/stack_frame.rb', line 64 def self.callstack(skip = 1) ret = [] caller(skip).each do |bt| ret.push(from_backtrace(bt)) end return ret end |
.from_backtrace(bt) ⇒ KXI::Reflection::StackFrame
Parses backtrace line into KXI::Reflection::StackFrame
75 76 77 78 |
# File 'lib/kxi/reflection/stack_frame.rb', line 75 def self.from_backtrace(bt) mt = /(?'file'.+?):(?'line'\d+)(:\s*in\s*`(?'context'.+?)')?/.match(bt) StackFrame.new(mt['file'], mt['line'].to_i, mt['context']) end |
Instance Method Details
#block? ⇒ Bool
Indicates whether frame is block
26 27 28 |
# File 'lib/kxi/reflection/stack_frame.rb', line 26 def block? @block != nil end |
#context ⇒ String
Returns the context of frame
20 21 22 |
# File 'lib/kxi/reflection/stack_frame.rb', line 20 def context @context end |
#file ⇒ String
Returns the file of frame
8 9 10 |
# File 'lib/kxi/reflection/stack_frame.rb', line 8 def file @file end |
#line ⇒ Number
Returns the line number of frame
14 15 16 |
# File 'lib/kxi/reflection/stack_frame.rb', line 14 def line @line end |
#method ⇒ String?
Returns containing method of frame; nil if none
32 33 34 35 36 37 |
# File 'lib/kxi/reflection/stack_frame.rb', line 32 def method return nil if @block != nil and @block[0] == '<' and @block[@block.length - 1] == '>' return @block unless @block == nil return nil if @context != nil and @context[0] == '<' and @context[@context.length - 1] == '>' @context end |
#to_s ⇒ String
Converts class to string
57 58 59 |
# File 'lib/kxi/reflection/stack_frame.rb', line 57 def to_s "#{@file}:#{@line}#{(@context != nil ? ": in `#{@context}'" : '')}" end |