Class: RailsMemoryProfiler::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/rails_memory_profiler/engine.rb

Class Method Summary collapse

Class Method Details

.mount_pathString?

Returns the path at which the engine is mounted in the host application, e.g. “/rails/memory”. Detected lazily on first call by scanning Rails.application.routes, then cached. Returns nil if the engine is not mounted.

Returns:

  • (String, nil)


19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rails_memory_profiler/engine.rb', line 19

def mount_path
  return @mount_path if @mount_path

  MOUNT_PATH_MUTEX.synchronize do
    @mount_path ||= begin
      mounted = Rails.application.routes.routes.find do |route|
        route.app.app == self rescue false
      end
      mounted&.path&.spec&.to_s&.gsub(/\([^)]*\)/, "")
    end
  end
end

.reset_mount_path!void

This method returns an undefined value.

Clears the cached mount path so it will be re-detected on the next call. Primarily used in tests.



36
37
38
# File 'lib/rails_memory_profiler/engine.rb', line 36

def reset_mount_path!
  MOUNT_PATH_MUTEX.synchronize { @mount_path = nil }
end