Module: Ace::Support::Config
- Defined in:
- lib/ace/support/config.rb,
lib/ace/support/config/cli.rb,
lib/ace/support/config/errors.rb,
lib/ace/support/config/version.rb,
lib/ace/support/config/models/config.rb,
lib/ace/support/config/atoms/deep_merger.rb,
lib/ace/support/config/atoms/yaml_parser.rb,
lib/ace/support/config/models/cascade_path.rb,
lib/ace/support/config/models/config_group.rb,
lib/ace/support/config/atoms/path_validator.rb,
lib/ace/support/config/molecules/yaml_loader.rb,
lib/ace/support/config/organisms/config_diff.rb,
lib/ace/support/config/atoms/path_rule_matcher.rb,
lib/ace/support/config/models/config_templates.rb,
lib/ace/support/config/molecules/config_finder.rb,
lib/ace/support/config/organisms/config_resolver.rb,
lib/ace/support/config/organisms/config_initializer.rb,
lib/ace/support/config/molecules/file_config_resolver.rb,
lib/ace/support/config/molecules/project_config_scanner.rb,
lib/ace/support/config/organisms/virtual_config_resolver.rb
Defined Under Namespace
Modules: Atoms, Models, Molecules, Organisms Classes: CLI, ConfigNotFoundError, Error, MergeStrategyError, PathError, YamlParseError
Constant Summary collapse
- DEFAULT_CONFIG_DIR =
Default folder name for user configuration
".ace"- DEFAULT_DEFAULTS_DIR =
Default folder name for gem defaults
".ace-defaults"- DEFAULT_PROJECT_MARKERS =
Default project root markers
%w[ .git Gemfile package.json Cargo.toml pyproject.toml go.mod .hg .svn Rakefile Makefile ].freeze
- VERSION =
'0.11.2'
Class Method Summary collapse
-
.create(config_dir: DEFAULT_CONFIG_DIR, defaults_dir: DEFAULT_DEFAULTS_DIR, gem_path: nil, merge_strategy: :replace, cache_namespaces: false, test_mode: nil, mock_config: nil) ⇒ Organisms::ConfigResolver
Create a new configuration resolver with customizable options.
-
.default_mock ⇒ Hash?
Thread-local mock configuration data to return in test mode.
-
.default_mock=(value) ⇒ Object
Set thread-local mock configuration data.
-
.find_project_root(start_path: nil, markers: DEFAULT_PROJECT_MARKERS) ⇒ String?
Find project root from a starting path.
-
.finder(config_dir: DEFAULT_CONFIG_DIR, defaults_dir: DEFAULT_DEFAULTS_DIR, gem_path: nil) ⇒ Molecules::ConfigFinder
Create a configuration finder for lower-level access.
-
.path_expander(source_dir:, project_root:) ⇒ Ace::Support::Fs::Atoms::PathExpander
Create a path expander with explicit context.
-
.reset_config! ⇒ void
Reset all cached configuration state.
-
.test_mode ⇒ Boolean?
Thread-local test mode state Uses Thread.current for true thread isolation in parallel test environments.
-
.test_mode=(value) ⇒ Object
Set thread-local test mode state.
-
.test_mode? ⇒ Boolean
Check if test mode is active.
-
.virtual_resolver(config_dir: DEFAULT_CONFIG_DIR, defaults_dir: DEFAULT_DEFAULTS_DIR, start_path: nil, gem_path: nil) ⇒ Organisms::VirtualConfigResolver
Create a virtual config resolver for path-based lookups.
Class Method Details
.create(config_dir: DEFAULT_CONFIG_DIR, defaults_dir: DEFAULT_DEFAULTS_DIR, gem_path: nil, merge_strategy: :replace, cache_namespaces: false, test_mode: nil, mock_config: nil) ⇒ Organisms::ConfigResolver
Create a new configuration resolver with customizable options
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/ace/support/config.rb', line 170 def create( config_dir: DEFAULT_CONFIG_DIR, defaults_dir: DEFAULT_DEFAULTS_DIR, gem_path: nil, merge_strategy: :replace, cache_namespaces: false, test_mode: nil, mock_config: nil ) # Determine effective test mode effective_test_mode = test_mode.nil? ? test_mode? : test_mode Organisms::ConfigResolver.new( config_dir: config_dir, defaults_dir: defaults_dir, gem_path: gem_path, merge_strategy: merge_strategy, cache_namespaces: cache_namespaces, test_mode: effective_test_mode, mock_config: mock_config || default_mock ) end |
.default_mock ⇒ Hash?
Thread-local mock configuration data to return in test mode
102 103 104 |
# File 'lib/ace/support/config.rb', line 102 def default_mock Thread.current[:ace_config_default_mock] end |
.default_mock=(value) ⇒ Object
Set thread-local mock configuration data
108 109 110 |
# File 'lib/ace/support/config.rb', line 108 def default_mock=(value) Thread.current[:ace_config_default_mock] = value end |
.find_project_root(start_path: nil, markers: DEFAULT_PROJECT_MARKERS) ⇒ String?
Find project root from a starting path
221 222 223 |
# File 'lib/ace/support/config.rb', line 221 def find_project_root(start_path: nil, markers: DEFAULT_PROJECT_MARKERS) Ace::Support::Fs::Molecules::ProjectRootFinder.find(start_path: start_path, markers: markers) end |
.finder(config_dir: DEFAULT_CONFIG_DIR, defaults_dir: DEFAULT_DEFAULTS_DIR, gem_path: nil) ⇒ Molecules::ConfigFinder
Create a configuration finder for lower-level access
199 200 201 202 203 204 205 |
# File 'lib/ace/support/config.rb', line 199 def finder(config_dir: DEFAULT_CONFIG_DIR, defaults_dir: DEFAULT_DEFAULTS_DIR, gem_path: nil) Molecules::ConfigFinder.new( config_dir: config_dir, defaults_dir: defaults_dir, gem_path: gem_path ) end |
.path_expander(source_dir:, project_root:) ⇒ Ace::Support::Fs::Atoms::PathExpander
Create a path expander with explicit context
212 213 214 |
# File 'lib/ace/support/config.rb', line 212 def (source_dir:, project_root:) Ace::Support::Fs::Atoms::PathExpander.new(source_dir: source_dir, project_root: project_root) end |
.reset_config! ⇒ void
This method returns an undefined value.
Reset all cached configuration state
Per ADR-022, this method allows test isolation by clearing all cached state in the configuration system.
272 273 274 275 276 |
# File 'lib/ace/support/config.rb', line 272 def reset_config! Ace::Support::Fs::Molecules::ProjectRootFinder.clear_cache! Thread.current[:ace_config_test_mode] = nil Thread.current[:ace_config_default_mock] = nil end |
.test_mode ⇒ Boolean?
Thread-local test mode state Uses Thread.current for true thread isolation in parallel test environments
90 91 92 |
# File 'lib/ace/support/config.rb', line 90 def test_mode Thread.current[:ace_config_test_mode] end |
.test_mode=(value) ⇒ Object
Set thread-local test mode state
96 97 98 |
# File 'lib/ace/support/config.rb', line 96 def test_mode=(value) Thread.current[:ace_config_test_mode] = value end |
.test_mode? ⇒ Boolean
Check if test mode is active
Test mode is active when:
-
Ace::Support::Config.test_mode is explicitly set to true
-
ACE_CONFIG_TEST_MODE environment variable is set to “1” or “true” (case-insensitive)
Note: We intentionally do NOT auto-detect based on Minitest being loaded, as that would break tests that need to test real filesystem access (like ace-config’s own tests). Use explicit opt-in instead.
Note: ENV lookup is intentionally NOT memoized to allow dynamic control of test_mode via environment variable changes at runtime.
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/ace/support/config.rb', line 126 def test_mode? # Note: test_mode (without ?) is the thread-local getter defined above, # not a recursive call - it reads from Thread.current[:ace_config_test_mode] return true if test_mode == true env_value = ENV["ACE_CONFIG_TEST_MODE"] return false if env_value.nil? return true if env_value == "1" return true if env_value.casecmp("true").zero? false end |
.virtual_resolver(config_dir: DEFAULT_CONFIG_DIR, defaults_dir: DEFAULT_DEFAULTS_DIR, start_path: nil, gem_path: nil) ⇒ Organisms::VirtualConfigResolver
Create a virtual config resolver for path-based lookups
VirtualConfigResolver provides a “virtual filesystem” view where nearest config file wins. Useful for finding presets and resources across the configuration cascade without loading/merging YAML content.
252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/ace/support/config.rb', line 252 def virtual_resolver( config_dir: DEFAULT_CONFIG_DIR, defaults_dir: DEFAULT_DEFAULTS_DIR, start_path: nil, gem_path: nil ) Organisms::VirtualConfigResolver.new( config_dir: config_dir, defaults_dir: defaults_dir, start_path: start_path, gem_path: gem_path ) end |