Class: RosettAi::Compiler::Backend

Inherits:
Object
  • Object
show all
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//target.yml.

Factory method .for(target_name) loads the profile and resolves the correct backend class from the Plugins::Registry.

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile) ⇒ Backend

Returns a new instance of Backend.



27
28
29
# File 'lib/rosett_ai/compiler/backend.rb', line 27

def initialize(profile)
  @profile = profile
end

Instance Attribute Details

#profileObject (readonly)

Returns the value of attribute profile.



25
26
27
# File 'lib/rosett_ai/compiler/backend.rb', line 25

def profile
  @profile
end

Class Method Details

.for(target_name) ⇒ Backend

Factory: load a target profile and instantiate the appropriate backend.

Parameters:

  • target_name (String, Symbol)

    engine/target identifier

Returns:

  • (Backend)

    the engine-specific backend instance

Raises:



36
37
38
39
40
# File 'lib/rosett_ai/compiler/backend.rb', line 36

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_extensionString

Return the output file extension for this backend.

Returns:

  • (String)


80
81
82
83
84
85
86
# File 'lib/rosett_ai/compiler/backend.rb', line 80

def file_extension
  case profile.output_format
  when 'json' then '.json'
  when 'yaml' then '.yml'
  else '.md'
  end
end

#generated_markerObject

Raises:

  • (NotImplementedError)


65
66
67
# File 'lib/rosett_ai/compiler/backend.rb', line 65

def generated_marker
  raise NotImplementedError, "#{self.class}#generated_marker must be implemented"
end

#managed_file?(path) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
72
73
74
75
76
# File 'lib/rosett_ai/compiler/backend.rb', line 69

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

Raises:

  • (NotImplementedError)


61
62
63
# File 'lib/rosett_ai/compiler/backend.rb', line 61

def render(_data)
  raise NotImplementedError, "#{self.class}#render must be implemented"
end