Class: RepoTender::CLI::Daemon::Helpers::Resolve

Inherits:
Data
  • Object
show all
Defined in:
lib/repo_tender/cli/daemon.rb,
lib/repo_tender/cli/daemon.rb

Overview

Detect the runtime paths the plist needs. The repo-tender install path matters because the plist stores an absolute β€˜bin_path` β€” that is the script launchd invokes. We resolve `bin_path` from the on-disk gem layout if we can, else fall back to the directory the daemon command was run from.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo_root:, mise_toml:, mise_bin:, ruby_bin:, bin_path:) ⇒ Resolve

Returns a new instance of Resolve.



89
90
91
# File 'lib/repo_tender/cli/daemon.rb', line 89

def initialize(repo_root:, mise_toml:, mise_bin:, ruby_bin:, bin_path:)
  super
end

Instance Attribute Details

#bin_pathObject (readonly)

Returns the value of attribute bin_path

Returns:

  • (Object)

    the current value of bin_path



88
89
90
# File 'lib/repo_tender/cli/daemon.rb', line 88

def bin_path
  @bin_path
end

#mise_binObject (readonly)

Returns the value of attribute mise_bin

Returns:

  • (Object)

    the current value of mise_bin



88
89
90
# File 'lib/repo_tender/cli/daemon.rb', line 88

def mise_bin
  @mise_bin
end

#mise_tomlObject (readonly)

Returns the value of attribute mise_toml

Returns:

  • (Object)

    the current value of mise_toml



88
89
90
# File 'lib/repo_tender/cli/daemon.rb', line 88

def mise_toml
  @mise_toml
end

#repo_rootObject (readonly)

Returns the value of attribute repo_root

Returns:

  • (Object)

    the current value of repo_root



88
89
90
# File 'lib/repo_tender/cli/daemon.rb', line 88

def repo_root
  @repo_root
end

#ruby_binObject (readonly)

Returns the value of attribute ruby_bin

Returns:

  • (Object)

    the current value of ruby_bin



88
89
90
# File 'lib/repo_tender/cli/daemon.rb', line 88

def ruby_bin
  @ruby_bin
end

Class Method Details

.detect(repo_root:) ⇒ Resolve

Parameters:

  • repo_root (String)

    absolute path of the working directory (where mise.toml is expected)

Returns:



294
295
296
297
298
299
300
# File 'lib/repo_tender/cli/daemon.rb', line 294

def self.detect(repo_root:)
  mise_bin = detect_mise_bin
  ruby_bin = detect_ruby_bin(repo_root, mise_bin)
  bin_path = detect_bin_path(repo_root)
  mise_toml = File.join(repo_root, "mise.toml")
  new(repo_root: repo_root, mise_toml: mise_toml, mise_bin: mise_bin, ruby_bin: ruby_bin, bin_path: bin_path)
end

.detect_bin_path(repo_root) ⇒ Object



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/repo_tender/cli/daemon.rb', line 323

def self.detect_bin_path(repo_root)
  path = ENV["REPO_TENDER_BIN_PATH"]
  return path if path && !path.empty?
  # Prefer the on-disk dev bin at `<repo_root>/bin/repo-tender`
  # β€” it's what the human runs during testing, and the gem is
  # typically not `gem install`ed in a source checkout.
  dev = File.join(repo_root, "bin", "repo-tender")
  return dev if File.exist?(dev)
  # Next, an installed binary on PATH.
  require "open3"
  out, _e, st = Open3.capture3("which", "repo-tender")
  return out.strip if st.success? && !out.strip.empty?
  # Last resort: the installed gem's bin (raises if not installed).
  Gem.bin_path("repo-tender", "repo-tender")
end

.detect_mise_binObject



302
303
304
305
306
307
308
# File 'lib/repo_tender/cli/daemon.rb', line 302

def self.detect_mise_bin
  path = ENV["REPO_TENDER_MISE_BIN"]
  return path if path && !path.empty?
  require "open3"
  out, _e, st = Open3.capture3("which", "mise")
  st.success? ? out.strip : "/opt/homebrew/bin/mise"
end

.detect_ruby_bin(repo_root, mise_bin) ⇒ Object



310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/repo_tender/cli/daemon.rb', line 310

def self.detect_ruby_bin(repo_root, mise_bin)
  path = ENV["REPO_TENDER_RUBY_BIN"]
  return path if path && !path.empty?
  # `mise exec -- which ruby` β€” but we avoid spawning in tests;
  # production path goes through here.
  require "open3"
  out, _e, st = Open3.capture3(mise_bin, "exec", "--", "which", "ruby", chdir: repo_root)
  return out.strip if st.success? && !out.strip.empty?
  # Fall back to the system ruby (last resort).
  out, _e, st = Open3.capture3("which", "ruby")
  st.success? ? out.strip : "/usr/bin/ruby"
end