Class: Space::Architect::SessionSync::Plist
- Inherits:
-
Object
- Object
- Space::Architect::SessionSync::Plist
- Defined in:
- lib/space_architect/session_sync/plist.rb
Overview
Hand-rolled launchd plist emitter for the session-sync agent, imitating Space::Src::Launchd::Plist's shape. Under launchd's bare PATH, a bare env-relative ruby binstub shebang resolves to macOS system Ruby instead of the caller's toolchain, so ProgramArguments names the interpreter explicitly (ruby_bin) rather than relying on shebang resolution — no mise wrapping needed, since the sync itself pins no toolchain at run time.
Constant Summary collapse
- DEFAULT_PATH =
"/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin"- HEADER =
<<~XML <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> XML
- FOOTER =
"</dict>\n</plist>\n"
Class Method Summary collapse
-
.call(label:, refresh_interval:, log_dir:, bin_path:, ruby_bin:, host:, env:) ⇒ String
The full plist XML.
Class Method Details
.call(label:, refresh_interval:, log_dir:, bin_path:, ruby_bin:, host:, env:) ⇒ String
Returns the full plist XML.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/space_architect/session_sync/plist.rb', line 35 def call(label:, refresh_interval:, log_dir:, bin_path:, ruby_bin:, host:, env:) raise ArgumentError, "label is required" if label.to_s.empty? raise ArgumentError, "refresh_interval must be > 0" unless refresh_interval.is_a?(Integer) && refresh_interval > 0 %w[log_dir bin_path ruby_bin].each do |k| v = binding.local_variable_get(k) raise ArgumentError, "#{k} must be absolute (got #{v.inspect})" unless v.is_a?(String) && File.absolute_path?(v) end raise ArgumentError, "host is required" if host.to_s.empty? raise ArgumentError, "env[#{SessionSync::TOKEN_ENV}] is required" if env.to_h[SessionSync::TOKEN_ENV].to_s.empty? out_log = File.join(log_dir, "#{label}.out.log") err_log = File.join(log_dir, "#{label}.err.log") body = +"" body << key("Label") << string(label) << "\n" body << key("ProgramArguments") << "\n" << array([ ruby_bin, bin_path, "sessions", "sync", "--host", host ]) body << key("EnvironmentVariables") << "\n" << dict({"PATH" => DEFAULT_PATH}.merge(env.to_h)) body << key("StartInterval") << integer(refresh_interval) << "\n" body << key("RunAtLoad") << boolean(true) << "\n" body << key("ProcessType") << string("Background") << "\n" body << key("StandardOutPath") << string(out_log) << "\n" body << key("StandardErrorPath") << string(err_log) << "\n" HEADER + body + FOOTER end |