Sha256: 5bd45d7dc83b429e747d078b693982b7207c588be0d7b208ddab9575acd1c686

Contents?: true

Size: 814 Bytes

Versions: 2

Compression:

Stored size: 814 Bytes

Contents

module MemoryProfiler
  class Helpers

    def initialize
      @gem_guess_cache = Hash.new
      @location_cache = Hash.new { |h,k| h[k] = Hash.new.compare_by_identity }
      @class_name_cache = Hash.new.compare_by_identity
    end

    def guess_gem(path)
      @gem_guess_cache[path] ||=
        if /(\/gems\/.*)*\/gems\/(?<gemname>[^\/]+)/ =~ path
          gemname
        elsif /\/rubygems[\.\/]/ =~ path
          "rubygems".freeze
        elsif /(?<app>[^\/]+\/(bin|app|lib))/ =~ path
          app
        else
          "other".freeze
        end
    end

    def lookup_location(file, line)
      @location_cache[file][line] ||= "#{file}:#{line}"
    end

    def lookup_class_name(klass)
      @class_name_cache[klass] ||= ((klass.is_a?(Class) && klass.name) || '<<Unknown>>').to_s
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
memory_profiler-0.9.8 lib/memory_profiler/helpers.rb
memory_profiler-0.9.7 lib/memory_profiler/helpers.rb