Class: RosettAi::Compiler::Backend
- Inherits:
-
Object
- Object
- RosettAi::Compiler::Backend
- Defined in:
- lib/rosett_ai/compiler/backend.rb
Overview
Abstract base class for compiler backends.
Backends transform compiled category data into target-specific output
formats. Each backend is paired with a TargetProfile loaded from
conf/engines/
Factory method .for(target_name) loads the profile and resolves the correct backend class from the Plugins::Registry.
Direct Known Subclasses
RosettAi::Compiler::Backends::AgentsMdBackend, RosettAi::Compiler::Backends::ClaudeBackend
Constant Summary collapse
- BUILTIN_BACKENDS =
Built-in backends that don't require an external engine gem. Lazy-loaded via lambdas to avoid circular requires.
{ 'agents_md' => -> { RosettAi::Compiler::Backends::AgentsMdBackend }, 'claude' => -> { RosettAi::Compiler::Backends::ClaudeBackend } }.freeze
Instance Attribute Summary collapse
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
Class Method Summary collapse
-
.for(target_name) ⇒ Backend
Factory: load a target profile and instantiate the appropriate backend.
Instance Method Summary collapse
- #file_extension ⇒ Object
- #generated_marker ⇒ Object
-
#initialize(profile) ⇒ Backend
constructor
A new instance of Backend.
- #managed_file?(path) ⇒ Boolean
- #render(_data) ⇒ Object
Constructor Details
#initialize(profile) ⇒ Backend
Returns a new instance of Backend.
26 27 28 |
# File 'lib/rosett_ai/compiler/backend.rb', line 26 def initialize(profile) @profile = profile end |
Instance Attribute Details
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
24 25 26 |
# File 'lib/rosett_ai/compiler/backend.rb', line 24 def profile @profile end |
Class Method Details
.for(target_name) ⇒ Backend
Factory: load a target profile and instantiate the appropriate backend.
35 36 37 38 39 |
# File 'lib/rosett_ai/compiler/backend.rb', line 35 def self.for(target_name) name = target_name.to_s profile = TargetProfile.load(name) resolve_backend_class(profile.backend).new(profile) end |
Instance Method Details
#file_extension ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/rosett_ai/compiler/backend.rb', line 77 def file_extension case profile.output_format when 'json' then '.json' when 'yaml' then '.yml' else '.md' end end |
#generated_marker ⇒ Object
64 65 66 |
# File 'lib/rosett_ai/compiler/backend.rb', line 64 def generated_marker raise NotImplementedError, "#{self.class}#generated_marker must be implemented" end |
#managed_file?(path) ⇒ Boolean
68 69 70 71 72 73 74 75 |
# File 'lib/rosett_ai/compiler/backend.rb', line 68 def managed_file?(path) return false unless File.exist?(path) first_line = File.open(path, &:readline) first_line.start_with?(generated_marker) rescue EOFError false end |
#render(_data) ⇒ Object
60 61 62 |
# File 'lib/rosett_ai/compiler/backend.rb', line 60 def render(_data) raise NotImplementedError, "#{self.class}#render must be implemented" end |