Class: Ace::Support::Config::Organisms::VirtualConfigResolver
- Inherits:
-
Object
- Object
- Ace::Support::Config::Organisms::VirtualConfigResolver
- Defined in:
- lib/ace/support/config/organisms/virtual_config_resolver.rb
Overview
Resolves configuration files using a cascade system Provides a virtual filesystem view where nearest config wins
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.
-
#start_path ⇒ Object
readonly
Returns the value of attribute start_path.
-
#virtual_map ⇒ Object
readonly
Returns the value of attribute virtual_map.
Instance Method Summary collapse
-
#config_directories ⇒ Array<String>
Get all discovered config directories in priority order.
-
#exists?(relative_path) ⇒ Boolean
Check if a relative path exists in the virtual map.
-
#glob(pattern) ⇒ Hash<String, String>
Get all files matching a pattern.
-
#initialize(config_dir: ".ace", defaults_dir: ".ace-defaults", start_path: nil, gem_path: nil) ⇒ VirtualConfigResolver
constructor
Initialize with configurable folder names.
-
#reload! ⇒ Object
Reload the virtual map (useful if config files change).
-
#resolve_path(relative_path) ⇒ String?
Get absolute path for a relative config path.
Constructor Details
#initialize(config_dir: ".ace", defaults_dir: ".ace-defaults", start_path: nil, gem_path: nil) ⇒ VirtualConfigResolver
Initialize with configurable folder names
17 18 19 20 21 22 23 |
# File 'lib/ace/support/config/organisms/virtual_config_resolver.rb', line 17 def initialize(config_dir: ".ace", defaults_dir: ".ace-defaults", start_path: nil, gem_path: nil) @config_dir = config_dir @defaults_dir = defaults_dir @start_path = start_path || Dir.pwd @gem_path = gem_path @virtual_map = build_virtual_map end |
Instance Attribute Details
#config_dir ⇒ Object (readonly)
Returns the value of attribute config_dir.
10 11 12 |
# File 'lib/ace/support/config/organisms/virtual_config_resolver.rb', line 10 def config_dir @config_dir end |
#defaults_dir ⇒ Object (readonly)
Returns the value of attribute defaults_dir.
10 11 12 |
# File 'lib/ace/support/config/organisms/virtual_config_resolver.rb', line 10 def defaults_dir @defaults_dir end |
#gem_path ⇒ Object (readonly)
Returns the value of attribute gem_path.
10 11 12 |
# File 'lib/ace/support/config/organisms/virtual_config_resolver.rb', line 10 def gem_path @gem_path end |
#start_path ⇒ Object (readonly)
Returns the value of attribute start_path.
10 11 12 |
# File 'lib/ace/support/config/organisms/virtual_config_resolver.rb', line 10 def start_path @start_path end |
#virtual_map ⇒ Object (readonly)
Returns the value of attribute virtual_map.
10 11 12 |
# File 'lib/ace/support/config/organisms/virtual_config_resolver.rb', line 10 def virtual_map @virtual_map end |
Instance Method Details
#config_directories ⇒ Array<String>
Get all discovered config directories in priority order
59 60 61 |
# File 'lib/ace/support/config/organisms/virtual_config_resolver.rb', line 59 def config_directories @config_directories ||= discover_config_directories end |
#exists?(relative_path) ⇒ Boolean
Check if a relative path exists in the virtual map
53 54 55 |
# File 'lib/ace/support/config/organisms/virtual_config_resolver.rb', line 53 def exists?(relative_path) @virtual_map.key?(normalize_path(relative_path)) end |
#glob(pattern) ⇒ Hash<String, String>
Get all files matching a pattern
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ace/support/config/organisms/virtual_config_resolver.rb', line 36 def glob(pattern) results = {} @virtual_map.each do |relative_path, absolute_path| # FNM_PATHNAME ensures * doesn't match / # FNM_DOTMATCH ensures hidden files are matched if pattern starts with . if File.fnmatch?(pattern, relative_path, File::FNM_PATHNAME | File::FNM_DOTMATCH) results[relative_path] = absolute_path end end results end |
#reload! ⇒ Object
Reload the virtual map (useful if config files change)
64 65 66 67 |
# File 'lib/ace/support/config/organisms/virtual_config_resolver.rb', line 64 def reload! @virtual_map = build_virtual_map @config_directories = nil end |
#resolve_path(relative_path) ⇒ String?
Get absolute path for a relative config path
28 29 30 31 |
# File 'lib/ace/support/config/organisms/virtual_config_resolver.rb', line 28 def resolve_path(relative_path) normalized = normalize_path(relative_path) @virtual_map[normalized] end |