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.



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

def initialize(profile)
  @profile = profile
end

Instance Attribute Details

#profileObject (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.

Parameters:

  • target_name (String, Symbol)

    engine/target identifier

Returns:

  • (Backend)

    the engine-specific backend instance

Raises:



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_extensionObject



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_markerObject

Raises:

  • (NotImplementedError)


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

Returns:

  • (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

Raises:

  • (NotImplementedError)


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

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