Module: Mbeditor::WorkspaceRootResolver

Defined in:
app/services/mbeditor/workspace_root_resolver.rb

Overview

Single source of truth for locating the workspace root. Used by both the HTTP controllers and the ActionCable channel so the git rev-parse subprocess runs at most once per process instead of once per call site.

Class Method Summary collapse

Class Method Details

.callObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/mbeditor/workspace_root_resolver.rb', line 16

def call
  configured = Mbeditor.configuration.workspace_root
  # Configured path intentionally bypasses the memo — tests and initializers
  # may change it at any time.
  return Pathname.new(configured.to_s) if configured.present?

  cached = @resolved_root
  return cached if cached

  MUTEX.synchronize do
    @resolved_root ||= begin
      rails_root = Rails.root.to_s
      out, _err, status = Open3.capture3("git", "-C", rails_root, "rev-parse", "--show-toplevel")
      Pathname.new(status.success? && out.strip.present? ? out.strip : rails_root)
    rescue StandardError
      Rails.root
    end
  end
end

.reset!Object



36
37
38
# File 'app/services/mbeditor/workspace_root_resolver.rb', line 36

def reset!
  MUTEX.synchronize { @resolved_root = nil }
end