Class: Canon::Config::ProfileLoader
- Inherits:
-
Object
- Object
- Canon::Config::ProfileLoader
- Defined in:
- lib/canon/config/profile_loader.rb
Overview
Loads configuration profiles from YAML files. Supports built-in profiles (shipped with the gem) and external file paths. Profiles can inherit from other profiles via the inherits key.
Constant Summary collapse
- PROFILES_DIR =
File.("profiles", __dir__).freeze
Class Method Summary collapse
-
.available_profiles ⇒ Object
List available built-in profile names.
-
.deep_merge(base, overlay) ⇒ Object
Deep merge two hashes.
-
.load(name_or_path) ⇒ Object
Load a profile by name (Symbol for built-in) or file path (String).
- .reset_cache! ⇒ Object
Class Method Details
.available_profiles ⇒ Object
List available built-in profile names.
23 24 25 26 27 28 29 |
# File 'lib/canon/config/profile_loader.rb', line 23 def available_profiles return [] unless Dir.exist?(PROFILES_DIR) Dir.glob(File.join(PROFILES_DIR, "*.yml")).map do |path| File.basename(path, ".yml").to_sym end.sort end |
.deep_merge(base, overlay) ⇒ Object
Deep merge two hashes. Arrays are replaced (not concatenated).
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/canon/config/profile_loader.rb', line 36 def deep_merge(base, ) result = base.dup .each do |key, value| result[key] = if result[key].is_a?(Hash) && value.is_a?(Hash) deep_merge(result[key], value) else value end end result end |
.load(name_or_path) ⇒ Object
Load a profile by name (Symbol for built-in) or file path (String). Returns a merged Hash with inheritance resolved.
17 18 19 20 |
# File 'lib/canon/config/profile_loader.rb', line 17 def load(name_or_path) key = cache_key(name_or_path) cache[key] ||= resolve(name_or_path, []) end |
.reset_cache! ⇒ Object
31 32 33 |
# File 'lib/canon/config/profile_loader.rb', line 31 def reset_cache! @cache = nil end |