Sha256: aaf0cf976051551b4d92c862de028edfef3d8088e5f79ede61ee0d88801a1fb5
Contents?: true
Size: 1 KB
Versions: 7
Compression:
Stored size: 1 KB
Contents
module Stackify::Backtrace ALL_TEXT_FROM_START_TO_FIRST_COLON_REGEXP = /\A([^:]+)/ NUMBER_BETWEEN_TWO_COLONS_REGEXP = /:(\d+):/ TEXT_AFTER_IN_BEFORE_END_REGEXP = /in\s`(\S+)'\z/ TEXT_AFTER_IN_BEFORE_END_REGEXP_ = /in\s(\S+)'\z/ def self.line_number backtrace_str backtrace_str[NUMBER_BETWEEN_TWO_COLONS_REGEXP, 1] end def self.method_name backtrace_str return nil unless backtrace_str backtrace_str[TEXT_AFTER_IN_BEFORE_END_REGEXP, 1] || backtrace_str[TEXT_AFTER_IN_BEFORE_END_REGEXP_, 1] end def self.file_name backtrace_str backtrace_str[ALL_TEXT_FROM_START_TO_FIRST_COLON_REGEXP, 1] end def self.stacktrace depth=5, backtrace return nil unless backtrace new_backtrace = [] backtrace.take(depth).each do |line| new_backtrace << { 'LineNum' => line_number(line), 'Method' => method_name(line), 'CodeFileName' => file_name(line) } end new_backtrace end def self.backtrace_in_line backtrace backtrace.join("\n") end end
Version data entries
7 entries across 7 versions & 1 rubygems