Class: MemoryProfiler::Helpers
- Inherits:
-
Object
- Object
- MemoryProfiler::Helpers
- Defined in:
- lib/memory_profiler/helpers.rb
Instance Method Summary collapse
- #guess_gem(path) ⇒ Object
-
#initialize ⇒ Helpers
constructor
A new instance of Helpers.
- #lookup_class_name(klass) ⇒ Object
- #lookup_location(file, line) ⇒ Object
- #lookup_string(obj) ⇒ Object
Constructor Details
#initialize ⇒ Helpers
Returns a new instance of Helpers.
4 5 6 7 8 9 |
# File 'lib/memory_profiler/helpers.rb', line 4 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 @string_cache = Hash.new end |
Instance Method Details
#guess_gem(path) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/memory_profiler/helpers.rb', line 11 def guess_gem(path) @gem_guess_cache[path] ||= if /(\/gems\/.*)*\/gems\/(?<gemname>[^\/]+)/ =~ path gemname elsif /\/rubygems[\.\/]/ =~ path "rubygems".freeze elsif /ruby\/2\.[^\/]+\/(?<stdlib>[^\/\.]+)/ =~ path stdlib elsif /(?<app>[^\/]+\/(bin|app|lib))/ =~ path app else "other".freeze end end |
#lookup_class_name(klass) ⇒ Object
30 31 32 |
# File 'lib/memory_profiler/helpers.rb', line 30 def lookup_class_name(klass) @class_name_cache[klass] ||= ((klass.is_a?(Class) && klass.name) || '<<Unknown>>').to_s end |
#lookup_location(file, line) ⇒ Object
26 27 28 |
# File 'lib/memory_profiler/helpers.rb', line 26 def lookup_location(file, line) @location_cache[file][line] ||= "#{file}:#{line}" end |
#lookup_string(obj) ⇒ Object
34 35 36 |
# File 'lib/memory_profiler/helpers.rb', line 34 def lookup_string(obj) @string_cache[obj] ||= String.new << obj end |