Class: RosettAi::Engines::BaseConfigCompiler
- Inherits:
-
Object
- Object
- RosettAi::Engines::BaseConfigCompiler
- Defined in:
- lib/rosett_ai/engines/base_config_compiler.rb
Overview
Abstract base class for engine config compilers.
Extracts shared compilation infrastructure from Claude::ConfigCompiler: file discovery, YAML loading, schema validation, checksum diffing, action determination, and result writing.
By default, compiling a scope MERGES with the existing target file, preserving entries not covered by any source YAML. Pass strict: true to get the old replace-all behaviour.
Subclasses must implement:
- #config_dir → Pathname to scope YAML directory
- #schema_path → Pathname to JSON Schema file
- #scope_router → object responding to #target_path(scope)
- #transform(data, scope) → [json_data, warnings]
- #output_format → Symbol (:json, :yaml)
Constant Summary collapse
- HEADER_KEYS =
Returns YAML header keys preserved in compiled output.
['name', 'scope', 'version', 'status', 'compatibility', 'author', 'created_at', 'modified_at', 'modified_by'].freeze
Instance Method Summary collapse
-
#compile ⇒ Object
Compile all scope files.
-
#compile_scope(path) ⇒ Object
Compile a single scope file.
-
#discover_scope_files ⇒ Object
Discover scope files in the engine's config directory.
-
#initialize(simulate: false, secret_resolver: nil, strict: false) ⇒ BaseConfigCompiler
constructor
A new instance of BaseConfigCompiler.
-
#write_results(results) ⇒ Object
Write compiled results to their target paths.
Constructor Details
#initialize(simulate: false, secret_resolver: nil, strict: false) ⇒ BaseConfigCompiler
Returns a new instance of BaseConfigCompiler.
36 37 38 39 40 41 |
# File 'lib/rosett_ai/engines/base_config_compiler.rb', line 36 def initialize(simulate: false, secret_resolver: nil, strict: false) @simulate = simulate @strict = strict @secret_resolver = secret_resolver || RosettAi::Config::SecretResolver.new @schema = load_schema end |
Instance Method Details
#compile ⇒ Object
Compile all scope files. Returns [RosettAi::Config::CompileResult].
44 45 46 |
# File 'lib/rosett_ai/engines/base_config_compiler.rb', line 44 def compile discover_scope_files.map { |path| compile_scope(path) } end |
#compile_scope(path) ⇒ Object
Compile a single scope file. Returns RosettAi::Config::CompileResult.
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 |
# File 'lib/rosett_ai/engines/base_config_compiler.rb', line 49 def compile_scope(path) warnings = [] data = load_and_validate(path) header = extract_header(data) scope = header['scope'] warnings.concat(check_compatibility(header, path)) json_data, transform_warnings = transform(data, scope) warnings.concat(transform_warnings) json_data = @secret_resolver.resolve_all(json_data) target = scope_router.target_path(scope) json_data, merge_warnings = merge_pass(target, json_data) warnings.concat(merge_warnings) action, diff = determine_action(target, json_data) RosettAi::Config::CompileResult.new( scope: scope, source_path: Pathname.new(path), target_path: target, json_data: json_data, warnings: warnings, action: action, diff: diff ) rescue RosettAi::Error, ArgumentError, JSON::Schema::ValidationError => e RosettAi::Config::CompileResult.new( scope: extract_scope_from_path(path), source_path: Pathname.new(path), target_path: nil, json_data: nil, warnings: [e.], action: :skipped, diff: nil ) end |
#discover_scope_files ⇒ Object
Discover scope files in the engine's config directory.
80 81 82 83 84 85 |
# File 'lib/rosett_ai/engines/base_config_compiler.rb', line 80 def discover_scope_files dir = config_dir return [] unless dir.exist? Dir.glob(dir.join('*.yml')) end |
#write_results(results) ⇒ Object
Write compiled results to their target paths.
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rosett_ai/engines/base_config_compiler.rb', line 88 def write_results(results) return results if @simulate results.each do |result| next unless result.changed? && result.target_path write_output(result.target_path, result.json_data) end results end |