class KXI::Reflection::StackFrame
Represents frame of call stack
Public Class Methods
Parses callstack into array of {KXI::Reflection::StackFrame} @param skip [Number] Number of callstack records to ignore @return [Array<KXI::Reflection::StackFrame>] Equivalent array of stack frames
# 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
Parses backtrace line into {KXI::Reflection::StackFrame} @param bt [String] Backtrace line @return [KXI::Reflection::StackFrame] Equivalent stack frame
# 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
Instantiates the {KXI::Reflection::StackFrame} class @param file [String] File of frame @param line [Number] Line number of frame @param context [String, nil] Context of frame
# 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
Public Instance Methods
Indicates whether frame is block @return [Bool] True if stack frame represents call to block; false otherwise
# File lib/kxi/reflection/stack_frame.rb, line 26 def block? @block != nil end
Returns the context of frame @return [String] Context of frame
# File lib/kxi/reflection/stack_frame.rb, line 20 def context @context end
Returns the file of frame @return [String] File of frame
# File lib/kxi/reflection/stack_frame.rb, line 8 def file @file end
Returns the line number of frame @return [Number] Line number of frame
# File lib/kxi/reflection/stack_frame.rb, line 14 def line @line end
Returns containing method of frame; nil if none @return [String, nil] Name of method that the stack frame represents
# 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
Converts class to string @return [String] Equivalent string
# File lib/kxi/reflection/stack_frame.rb, line 57 def to_s "#{@file}:#{@line}#{(@context != nil ? ": in `#{@context}'" : '')}" end