Class: MywayConfig::Loaders::XdgConfigLoader
- Inherits:
-
Anyway::Loaders::Base
- Object
- Anyway::Loaders::Base
- MywayConfig::Loaders::XdgConfigLoader
- Defined in:
- lib/myway_config/loaders/xdg_config_loader.rb
Overview
XDG Base Directory Specification loader for Anyway Config
Loads configuration from XDG-compliant paths:
- $XDG_CONFIG_HOME/app/app.yml (if XDG_CONFIG_HOME is set)
- ~/.config/app/app.yml (XDG default fallback)
On macOS, also checks: 3. ~/Library/Application Support/app/app.yml
This loader runs BEFORE the project-local config loader, so project configs take precedence over user-global configs.
Class Method Summary collapse
-
.config_paths(name) ⇒ Array<String>
Returns all XDG config paths to check for a given app name.
-
.find_config_file(name) ⇒ String?
Find the first existing config file for the given app name.
Instance Method Summary collapse
Class Method Details
.config_paths(name) ⇒ Array<String>
Returns all XDG config paths to check for a given app name
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/myway_config/loaders/xdg_config_loader.rb', line 33 def config_paths(name) paths = [] # macOS Application Support (lowest priority for XDG loader) if macos? macos_path = File.("~/Library/Application Support/#{name}") paths << macos_path if Dir.exist?(File.dirname(macos_path)) end # XDG default: ~/.config/{name} xdg_default = File.("~/.config/#{name}") paths << xdg_default # XDG_CONFIG_HOME override (highest priority for XDG loader) if ENV['XDG_CONFIG_HOME'] && !ENV['XDG_CONFIG_HOME'].empty? xdg_home = File.join(ENV['XDG_CONFIG_HOME'], name.to_s) paths << xdg_home unless xdg_home == xdg_default end paths end |
.find_config_file(name) ⇒ String?
Find the first existing config file for the given app name
59 60 61 62 63 64 65 |
# File 'lib/myway_config/loaders/xdg_config_loader.rb', line 59 def find_config_file(name) config_paths(name).reverse_each do |dir| file = File.join(dir, "#{name}.yml") return file if File.exist?(file) end nil end |
Instance Method Details
#call(name:, **_options) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/myway_config/loaders/xdg_config_loader.rb', line 74 def call(name:, **) config_file = self.class.find_config_file(name) return {} unless config_file trace!(:xdg, path: config_file) do load_yaml(config_file, name) end end |