Class: RepoTender::Paths
- Inherits:
-
Object
- Object
- RepoTender::Paths
- Defined in:
- lib/repo_tender/paths.rb
Overview
XDG-aware path resolution. Honors $XDG_CONFIG_HOME / $XDG_STATE_HOME overrides (and a caller-supplied environment hash for testability); otherwise falls back to the XDG defaults (~/.config, ~/.local/state).
‘base_dir` is the on-disk home for the evergreen clones ($BASE/:host/:owner/:repo). It defaults to ~/src/evergreen/ and is resolved from the config at call time (passed in as an argument here so this module owns nothing about config storage).
Constant Summary collapse
- APP_NAME =
"repo-tender"- DEFAULT_BASE_DIR =
File.("~/src/evergreen")
Instance Method Summary collapse
-
#base_dir ⇒ Object
Default ‘base_dir` is ~/src/evergreen (per PRD §3.1).
- #config_dir ⇒ Object
- #config_file ⇒ Object
- #config_home ⇒ Object
-
#ensure! ⇒ Object
Ensure the on-disk directories exist.
-
#initialize(environment: ENV, base_dir: nil) ⇒ Paths
constructor
A new instance of Paths.
-
#launch_agents_dir ⇒ Object
Per-user launchd agent directory.
- #log_dir ⇒ Object
- #state_dir ⇒ Object
- #state_file ⇒ Object
- #state_home ⇒ Object
Constructor Details
#initialize(environment: ENV, base_dir: nil) ⇒ Paths
Returns a new instance of Paths.
20 21 22 23 |
# File 'lib/repo_tender/paths.rb', line 20 def initialize(environment: ENV, base_dir: nil) @environment = environment @base_dir = base_dir end |
Instance Method Details
#base_dir ⇒ Object
Default ‘base_dir` is ~/src/evergreen (per PRD §3.1). Callers may override by passing one to the constructor (e.g. from loaded config).
52 53 54 |
# File 'lib/repo_tender/paths.rb', line 52 def base_dir @base_dir || DEFAULT_BASE_DIR end |
#config_dir ⇒ Object
29 |
# File 'lib/repo_tender/paths.rb', line 29 def config_dir = File.join(config_home, APP_NAME) |
#config_file ⇒ Object
31 |
# File 'lib/repo_tender/paths.rb', line 31 def config_file = File.join(config_dir, "config.yaml") |
#config_home ⇒ Object
25 |
# File 'lib/repo_tender/paths.rb', line 25 def config_home = xdg.config_home.to_s |
#ensure! ⇒ Object
Ensure the on-disk directories exist. The config file itself is optional and created lazily by Config::Store; we only ensure parent dirs. Idempotent.
59 60 61 62 63 64 |
# File 'lib/repo_tender/paths.rb', line 59 def ensure! FileUtils.mkdir_p(config_dir) FileUtils.mkdir_p(state_dir) FileUtils.mkdir_p(log_dir) self end |
#launch_agents_dir ⇒ Object
Per-user launchd agent directory. The user’s ‘~/Library/LaunchAgents/` (PRD §3.2; slice-4 Lane 01). The path is resolved from the env’s HOME so tests can inject a temp HOME via ‘Paths.new(environment:)` and assert that install/uninstall NEVER writes to the real `~/Library/LaunchAgents` (gate G3).
45 46 47 48 |
# File 'lib/repo_tender/paths.rb', line 45 def launch_agents_dir home = @environment["HOME"] || Dir.home File.join(home, "Library", "LaunchAgents") end |
#log_dir ⇒ Object
37 |
# File 'lib/repo_tender/paths.rb', line 37 def log_dir = File.join(state_dir, "logs") |
#state_dir ⇒ Object
33 |
# File 'lib/repo_tender/paths.rb', line 33 def state_dir = File.join(state_home, APP_NAME) |
#state_file ⇒ Object
35 |
# File 'lib/repo_tender/paths.rb', line 35 def state_file = File.join(state_dir, "state.yaml") |
#state_home ⇒ Object
27 |
# File 'lib/repo_tender/paths.rb', line 27 def state_home = xdg.state_home.to_s |