Sha256: 1e8529ebbbfd078d863a75eb4e5bbb0029c148e8659aad0a03ffcc2c41669557

Contents?: true

Size: 1.43 KB

Versions: 58

Compression:

Stored size: 1.43 KB

Contents

module Patches
  module BetterErrors
    class StackFrame
      # correct links to tmp files so that they point
      # to the original file and line
      module TmpPath
        @map = {} # cache tmp path mapping

        class << self
          def included klass
            klass.class_eval do
              remove_method :initialize
            end
          end

          def corrections filename
            @map[filename] ||= real_filename_and_line_offset filename
            yield(*@map[filename])
          end

          def real_filename_and_line_offset filename
            File.open(filename) do |file|
              file.each_line.with_index do |line, i|
                if line =~ /pulled from ([\S]+) ~~/
                  return Regexp.last_match(1), i + 1
                end
              end
            end
            [filename, 0]
          end
        end

        def initialize filename, line, name, frame_binding=nil
          @filename = filename
          @line = line
          @name = name
          @frame_binding = frame_binding

          correct_tmp_file if tmp_file?
          set_pretty_method_name if frame_binding
        end

        def tmp_file?
          @filename.include? "/tmp/"
        end

        def correct_tmp_file
          TmpPath.corrections(@filename) do |real_path, line_offset|
            @filename = real_path
            @line -= line_offset
          end
        end
      end
    end
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
card-1.101.4 config/initializers/02_patches/better_errors.rb
card-1.101.3 config/initializers/02_patches/better_errors.rb
card-1.101.2 config/initializers/02_patches/better_errors.rb
card-1.101.1 config/initializers/02_patches/better_errors.rb
card-1.101.0 config/initializers/02_patches/better_errors.rb
card-1.100.0 config/initializers/02_patches/better_errors.rb
card-1.99.6 config/initializers/02_patches/better_errors.rb
card-1.99.5 config/initializers/02_patches/better_errors.rb
card-1.99.4 config/initializers/02_patches/better_errors.rb
card-1.99.3 config/initializers/02_patches/better_errors.rb
card-1.99.2 config/initializers/02_patches/better_errors.rb
card-1.99.1 config/initializers/02_patches/better_errors.rb
card-1.99.0 config/initializers/02_patches/better_errors.rb
card-1.98.3 config/initializers/02_patches/better_errors.rb
card-1.98.2 config/initializers/02_patches/better_errors.rb
card-1.98.1 config/initializers/02_patches/better_errors.rb
card-1.98.0 config/initializers/02_patches/better_errors.rb
card-1.97.0.1 config/initializers/02_patches/better_errors.rb
card-1.97.0 config/initializers/02_patches/better_errors.rb
card-1.96.8 config/initializers/02_patches/better_errors.rb