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

Version Path
stackify-api-ruby-2.1.0 lib/stackify/utils/backtrace.rb
stackify-api-ruby-2.1.0.beta1 lib/stackify/utils/backtrace.rb
stackify-api-ruby-2.0.0 lib/stackify/utils/backtrace.rb
stackify-api-ruby-1.3.0.beta1 lib/stackify/utils/backtrace.rb
stackify-api-ruby-1.2.10 lib/stackify/utils/backtrace.rb
stackify-api-ruby-1.2.9 lib/stackify/utils/backtrace.rb
stackify-api-ruby-1.2.7 lib/stackify/utils/backtrace.rb