Class: Ace::Retro::Molecules::RetroConfigLoader
- Inherits:
-
Object
- Object
- Ace::Retro::Molecules::RetroConfigLoader
- Defined in:
- lib/ace/retro/molecules/retro_config_loader.rb
Overview
Loads and merges configuration for ace-retro from the cascade: .ace-defaults/retro/config.yml (gem) -> ~/.ace/retro/config.yml (user) -> .ace/retro/config.yml (project)
Constant Summary collapse
- DEFAULT_ROOT_DIR =
".ace-retros"
Class Method Summary collapse
-
.load(gem_root: nil) ⇒ Hash
Load configuration with cascade merge.
-
.root_dir(config = nil) ⇒ String
Get the root directory for retros.
Instance Method Summary collapse
-
#initialize(gem_root:) ⇒ RetroConfigLoader
constructor
A new instance of RetroConfigLoader.
-
#load ⇒ Hash
Load and merge configuration.
Constructor Details
#initialize(gem_root:) ⇒ RetroConfigLoader
Returns a new instance of RetroConfigLoader.
23 24 25 |
# File 'lib/ace/retro/molecules/retro_config_loader.rb', line 23 def initialize(gem_root:) @gem_root = gem_root end |
Class Method Details
.load(gem_root: nil) ⇒ Hash
Load configuration with cascade merge
17 18 19 20 21 |
# File 'lib/ace/retro/molecules/retro_config_loader.rb', line 17 def self.load(gem_root: nil) gem_root ||= File.("../../../..", __dir__) # lib/ace/retro/molecules/ → 4 levels up to gem root new(gem_root: gem_root).load end |
.root_dir(config = nil) ⇒ String
Get the root directory for retros
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ace/retro/molecules/retro_config_loader.rb', line 38 def self.root_dir(config = nil) config ||= load dir = config.dig("retro", "root_dir") || DEFAULT_ROOT_DIR if dir.start_with?("/") dir else File.join(Ace::Support::Fs::Molecules::ProjectRootFinder.find_or_current, dir) end end |
Instance Method Details
#load ⇒ Hash
Load and merge configuration
29 30 31 32 33 |
# File 'lib/ace/retro/molecules/retro_config_loader.rb', line 29 def load config = load_defaults config = deep_merge(config, load_user_config) deep_merge(config, load_project_config) end |