Class: Ace::Support::Config::Molecules::FileConfigResolver
- Inherits:
-
Object
- Object
- Ace::Support::Config::Molecules::FileConfigResolver
- Defined in:
- lib/ace/support/config/molecules/file_config_resolver.rb
Overview
Resolve effective config for a given file path using distributed configs and path rules
Instance Attribute Summary collapse
-
#config_dir ⇒ Object
readonly
Returns the value of attribute config_dir.
-
#defaults_dir ⇒ Object
readonly
Returns the value of attribute defaults_dir.
-
#gem_path ⇒ Object
readonly
Returns the value of attribute gem_path.
-
#merge_strategy ⇒ Object
readonly
Returns the value of attribute merge_strategy.
Instance Method Summary collapse
-
#initialize(config_dir: ".ace", defaults_dir: ".ace-defaults", gem_path: nil, merge_strategy: :replace) ⇒ FileConfigResolver
constructor
A new instance of FileConfigResolver.
-
#resolve(file_path, namespace: "git", filename: "commit", project_root: nil) ⇒ Models::ConfigGroup
Resolve config for a file.
Constructor Details
#initialize(config_dir: ".ace", defaults_dir: ".ace-defaults", gem_path: nil, merge_strategy: :replace) ⇒ FileConfigResolver
Returns a new instance of FileConfigResolver.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ace/support/config/molecules/file_config_resolver.rb', line 13 def initialize( config_dir: ".ace", defaults_dir: ".ace-defaults", gem_path: nil, merge_strategy: :replace ) @config_dir = config_dir @defaults_dir = defaults_dir @gem_path = gem_path @merge_strategy = merge_strategy end |
Instance Attribute Details
#config_dir ⇒ Object (readonly)
Returns the value of attribute config_dir.
11 12 13 |
# File 'lib/ace/support/config/molecules/file_config_resolver.rb', line 11 def config_dir @config_dir end |
#defaults_dir ⇒ Object (readonly)
Returns the value of attribute defaults_dir.
11 12 13 |
# File 'lib/ace/support/config/molecules/file_config_resolver.rb', line 11 def defaults_dir @defaults_dir end |
#gem_path ⇒ Object (readonly)
Returns the value of attribute gem_path.
11 12 13 |
# File 'lib/ace/support/config/molecules/file_config_resolver.rb', line 11 def gem_path @gem_path end |
#merge_strategy ⇒ Object (readonly)
Returns the value of attribute merge_strategy.
11 12 13 |
# File 'lib/ace/support/config/molecules/file_config_resolver.rb', line 11 def merge_strategy @merge_strategy end |
Instance Method Details
#resolve(file_path, namespace: "git", filename: "commit", project_root: nil) ⇒ Models::ConfigGroup
Resolve config for a file
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ace/support/config/molecules/file_config_resolver.rb', line 31 def resolve(file_path, namespace: "git", filename: "commit", project_root: nil) raise ArgumentError, "file_path cannot be nil or empty" if file_path.nil? || file_path.to_s.empty? start_path = resolve_start_path(file_path) project_root = normalize_path(project_root || detect_project_root(start_path) || start_path) relative_path = to_relative_path(file_path, project_root) distributed_config_path = find_distributed_config(start_path, project_root, namespace, filename) if distributed_config_path && project_root root_config_dir = File.join(project_root, config_dir.to_s) root_prefix = normalize_path(root_config_dir) + File::SEPARATOR if normalize_path(distributed_config_path).start_with?(root_prefix) distributed_config_path = nil end end config = load_cascade_config(start_path, project_root, namespace, filename) base_data = extract_config_data(config) # Check path rules FIRST (before distributed config scope) matched = match_path_rule(base_data, relative_path, project_root) if matched resolved = merge_rule_overrides(strip_paths_section(base_data), matched.config) return Models::ConfigGroup.new( name: matched.name, source: primary_source_path(config, namespace, filename, start_path, project_root), config: resolved, rule_config: matched.config, # Raw rule config for grouping (ignores cascade differences) files: [relative_path] ) end # Fall back to distributed config scope if present if distributed_config_path resolved = strip_paths_section(base_data) scope_name = scope_name_from_config_path(distributed_config_path, project_root) return Models::ConfigGroup.new( name: scope_name, source: distributed_config_path, config: resolved, files: [relative_path] ) end Models::ConfigGroup.new( name: Models::ConfigGroup::DEFAULT_SCOPE_NAME, source: primary_source_path(config, namespace, filename, start_path, project_root), config: strip_paths_section(base_data), files: [relative_path] ) end |