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. Unlike that emitter, this one does
NOT wrap the invocation in mise/ruby toolchain resolution: the
architect executable is a rubygems binstub (or the dev exe/architect
script, which sets up Bundler itself) and needs no toolchain pinning to
run non-interactively, so ProgramArguments invokes it directly.
Constant Summary collapse
- 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:, host:, env:) ⇒ String
The full plist XML.
Class Method Details
.call(label:, refresh_interval:, log_dir:, bin_path:, host:, env:) ⇒ String
Returns the full plist XML.
30 31 32 33 34 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 |
# File 'lib/space_architect/session_sync/plist.rb', line 30 def call(label:, refresh_interval:, log_dir:, bin_path:, 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].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([ bin_path, "sessions", "sync", "--host", host ]) body << key("EnvironmentVariables") << "\n" << dict(env) 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 |