Module: Ace::Core

Defined in:
lib/ace/core/atoms/config_summary.rb,
lib/ace/core.rb,
lib/ace/core/errors.rb,
lib/ace/core/version.rb,
lib/ace/core/atoms/env_parser.rb,
lib/ace/core/config_discovery.rb,
lib/ace/core/atoms/file_reader.rb,
lib/ace/core/atoms/glob_expander.rb,
lib/ace/core/molecules/env_loader.rb,
lib/ace/core/atoms/template_parser.rb,
lib/ace/core/atoms/command_executor.rb,
lib/ace/core/atoms/process_terminator.rb,
lib/ace/core/cli/config_summary_mixin.rb,
lib/ace/core/molecules/file_aggregator.rb,
lib/ace/core/molecules/output_formatter.rb,
lib/ace/core/organisms/environment_manager.rb,
lib/ace/core/molecules/prompt_cache_manager.rb,
lib/ace/core/molecules/frontmatter_free_policy.rb

Overview

Core functionality for ACE gems

Defined Under Namespace

Modules: Atoms, CLI, Molecules, Organisms Classes: ConfigDiscovery, ConfigInvalidError, EnvParseError, Error

Constant Summary collapse

VERSION =
'0.29.8'

Class Method Summary collapse

Class Method Details

.clear_env_cacheObject

Clear the cascade cache (useful for testing or reloading)



100
101
102
# File 'lib/ace/core.rb', line 100

def clear_env_cache
  @cascade_vars = nil
end

.configModels::Config

Resolve configuration with cascade using ace-config

Returns:

  • (Models::Config)

    Resolved configuration



28
29
30
# File 'lib/ace/core.rb', line 28

def config
  cached_resolver.resolve
end

.create_default_config(path = "./.ace/core/config.yml") ⇒ Models::Config

Create default configuration

Parameters:

  • path (String) (defaults to: "./.ace/core/config.yml")

    Where to create config

Returns:

  • (Models::Config)

    Created config



75
76
77
# File 'lib/ace/core.rb', line 75

def create_default_config(path = "./.ace/core/config.yml")
  ::Ace::Support::Config::Organisms::ConfigResolver.create_default(path)
end

.environment(root: Dir.pwd) ⇒ Organisms::EnvironmentManager

Get environment manager

Parameters:

  • root (String) (defaults to: Dir.pwd)

    Project root

Returns:



82
83
84
# File 'lib/ace/core.rb', line 82

def environment(root: Dir.pwd)
  Organisms::EnvironmentManager.new(root_path: root)
end

.get(namespace_or_keys, *keys, file: nil) ⇒ Object

Get configuration value by key path or namespace

Parameters:

  • namespace_or_keys (String, Symbol, Array)

    Namespace name or key path

  • file (String, nil) (defaults to: nil)

    Optional file name for namespace

  • keys (Array<String,Symbol>)

    Additional key path after namespace

Returns:

  • (Object)

    Configuration value



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ace/core.rb', line 37

def get(namespace_or_keys, *keys, file: nil)
  resolver = cached_resolver

  # If first arg looks like a namespace, resolve it
  if namespace_or_keys.is_a?(String) && namespace_or_keys.match?(/^[a-z]+$/)
    config = if file
      # Use resolve_namespace for single-file case (cleaner API)
      resolver.resolve_namespace(namespace_or_keys, filename: file)
    else
      # Use resolve_file for glob pattern case (resolve_namespace doesn't support globs)
      resolver.resolve_file(namespace_glob_patterns(namespace_or_keys))
    end
    keys.empty? ? config.data : config.get(*keys)
  else
    # Traditional key path lookup
    resolver.get(namespace_or_keys, *keys)
  end
end

.get_env(key, default = nil) ⇒ String, Object

Get environment variable from cascade without polluting ENV First checks ENV, then loads from .ace/.env cascade

Parameters:

  • key (String)

    Environment variable name

  • default (Object) (defaults to: nil)

    Default value if not found

Returns:

  • (String, Object)

    Variable value or default



91
92
93
94
95
96
97
# File 'lib/ace/core.rb', line 91

def get_env(key, default = nil)
  # Check ENV first for already-set variables
  return ENV[key] if ENV.key?(key) && !ENV[key].to_s.empty?

  # Load from cascade (cached for performance)
  cascade_vars[key] || default
end

.load_environment(root: Dir.pwd) ⇒ Hash

Load environment variables

Parameters:

  • root (String) (defaults to: Dir.pwd)

    Project root path

Returns:

  • (Hash)

    Loaded variables



67
68
69
70
# File 'lib/ace/core.rb', line 67

def load_environment(root: Dir.pwd)
  manager = Organisms::EnvironmentManager.new(root_path: root)
  manager.load
end

.namespace_glob_patterns(namespace) ⇒ Array<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build glob patterns for all YAML files in a namespace directory

Parameters:

  • namespace (String)

    Namespace name

Returns:

  • (Array<String>)

    Glob patterns for .yml and .yaml files



60
61
62
# File 'lib/ace/core.rb', line 60

def namespace_glob_patterns(namespace)
  ["#{namespace}/*.yml", "#{namespace}/*.yaml"]
end

.reset_config!Object

Reset all cached configuration state Per ADR-022, this method allows test isolation



106
107
108
109
110
# File 'lib/ace/core.rb', line 106

def reset_config!
  @cached_resolver = nil
  ::Ace::Support::Config.reset_config!
  clear_env_cache
end