Class: Space::Src::CLI::Daemon::Helpers::Resolve
- Inherits:
-
Data
- Object
- Data
- Space::Src::CLI::Daemon::Helpers::Resolve
- Defined in:
- lib/space_src/cli/daemon.rb,
lib/space_src/cli/daemon.rb
Overview
Detect the runtime paths the plist needs. The src 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
-
#bin_path ⇒ Object
readonly
Returns the value of attribute bin_path.
-
#mise_bin ⇒ Object
readonly
Returns the value of attribute mise_bin.
-
#mise_toml ⇒ Object
readonly
Returns the value of attribute mise_toml.
-
#repo_root ⇒ Object
readonly
Returns the value of attribute repo_root.
-
#ruby_bin ⇒ Object
readonly
Returns the value of attribute ruby_bin.
Class Method Summary collapse
- .detect(repo_root:) ⇒ Resolve
- .detect_bin_path(repo_root) ⇒ Object
- .detect_mise_bin ⇒ Object
- .detect_ruby_bin(repo_root, mise_bin) ⇒ Object
Instance Method Summary collapse
-
#initialize(repo_root:, mise_toml:, mise_bin:, ruby_bin:, bin_path:) ⇒ Resolve
constructor
A new instance of Resolve.
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/space_src/cli/daemon.rb', line 89 def initialize(repo_root:, mise_toml:, mise_bin:, ruby_bin:, bin_path:) super end |
Instance Attribute Details
#bin_path ⇒ Object (readonly)
Returns the value of attribute bin_path
88 89 90 |
# File 'lib/space_src/cli/daemon.rb', line 88 def bin_path @bin_path end |
#mise_bin ⇒ Object (readonly)
Returns the value of attribute mise_bin
88 89 90 |
# File 'lib/space_src/cli/daemon.rb', line 88 def mise_bin @mise_bin end |
#mise_toml ⇒ Object (readonly)
Returns the value of attribute mise_toml
88 89 90 |
# File 'lib/space_src/cli/daemon.rb', line 88 def mise_toml @mise_toml end |
#repo_root ⇒ Object (readonly)
Returns the value of attribute repo_root
88 89 90 |
# File 'lib/space_src/cli/daemon.rb', line 88 def repo_root @repo_root end |
#ruby_bin ⇒ Object (readonly)
Returns the value of attribute ruby_bin
88 89 90 |
# File 'lib/space_src/cli/daemon.rb', line 88 def ruby_bin @ruby_bin end |
Class Method Details
.detect(repo_root:) ⇒ Resolve
309 310 311 312 313 314 315 |
# File 'lib/space_src/cli/daemon.rb', line 309 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
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/space_src/cli/daemon.rb', line 338 def self.detect_bin_path(repo_root) path = ENV["SPACE_SRC_BIN_PATH"] return path if path && !path.empty? # Prefer the on-disk dev bin at `<repo_root>/exe/src` # — 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, "exe", "src") return dev if File.exist?(dev) # Next, an installed binary on PATH. require "open3" out, _e, st = Open3.capture3("which", "src") return out.strip if st.success? && !out.strip.empty? # Last resort: the installed gem's bin (raises if not installed). Gem.bin_path("space-architect", "src") end |
.detect_mise_bin ⇒ Object
317 318 319 320 321 322 323 |
# File 'lib/space_src/cli/daemon.rb', line 317 def self.detect_mise_bin path = ENV["SPACE_SRC_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
325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/space_src/cli/daemon.rb', line 325 def self.detect_ruby_bin(repo_root, mise_bin) path = ENV["SPACE_SRC_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 |