Class: SolidAgent::AgentManifest::ExporterRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/solid_agent/agent_manifest/exporter_registry.rb

Overview

ExporterRegistry manages format exporters for converting Manifests to various formats.

Examples:

Register an exporter

ExporterRegistry.register(:agent_md, AgentMdExporter)

Export a manifest

content = ExporterRegistry.export(manifest, :dotprompt)

Export to file

ExporterRegistry.export_to_file(manifest, :agent_md, "agent.agent.md")

Class Method Summary collapse

Class Method Details

.convert(input_path, output_format, output_path = nil) ⇒ String

Convert between formats

Parameters:

  • input_path (String)

    Source file path

  • output_format (Symbol, String)

    Target format

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

    Output path (auto-generated if nil)

Returns:

  • (String)

    Output path



88
89
90
91
92
93
# File 'lib/solid_agent/agent_manifest/exporter_registry.rb', line 88

def convert(input_path, output_format, output_path = nil)
  manifest = ParserRegistry.parse(input_path)

  output_path ||= generate_output_path(input_path, output_format)
  export_to_file(manifest, output_format, output_path)
end

.export(manifest, format, **options) ⇒ String

Export a manifest to a format string

Parameters:

  • manifest (Manifest)

    The manifest to export

  • format (Symbol, String)

    Target format

  • options (Hash)

    Format-specific options

Returns:

  • (String)

    Exported content



64
65
66
67
# File 'lib/solid_agent/agent_manifest/exporter_registry.rb', line 64

def export(manifest, format, **options)
  exporter = exporter_for(format)
  exporter.export(manifest, **options)
end

.export_to_file(manifest, format, path, **options) ⇒ String

Export a manifest to a file

Parameters:

  • manifest (Manifest)

    The manifest to export

  • format (Symbol, String)

    Target format

  • path (String)

    Output file path

  • options (Hash)

    Format-specific options

Returns:

  • (String)

    The path written to



76
77
78
79
80
# File 'lib/solid_agent/agent_manifest/exporter_registry.rb', line 76

def export_to_file(manifest, format, path, **options)
  content = export(manifest, format, **options)
  File.write(path, content, encoding: "UTF-8")
  path
end

.exporter_for(format) ⇒ Class

Get the exporter for a format

Parameters:

  • format (Symbol, String)

    Format name

Returns:

  • (Class)

    Exporter class

Raises:



38
39
40
41
# File 'lib/solid_agent/agent_manifest/exporter_registry.rb', line 38

def exporter_for(format)
  format_sym = format.to_sym
  exporters[format_sym] || raise(UnknownFormatError, "Unknown export format: #{format}")
end

.exportersHash<Symbol, Class>

Registered exporters by format name

Returns:

  • (Hash<Symbol, Class>)


21
22
23
# File 'lib/solid_agent/agent_manifest/exporter_registry.rb', line 21

def exporters
  @exporters ||= {}
end

.formatsArray<Symbol>

List all registered format names

Returns:

  • (Array<Symbol>)


54
55
56
# File 'lib/solid_agent/agent_manifest/exporter_registry.rb', line 54

def formats
  exporters.keys
end

.register(format, exporter_class) ⇒ Object

Register an exporter for a format

Parameters:

  • format (Symbol)

    Format name

  • exporter_class (Class)

    Exporter class



29
30
31
# File 'lib/solid_agent/agent_manifest/exporter_registry.rb', line 29

def register(format, exporter_class)
  exporters[format.to_sym] = exporter_class
end

.supports?(format) ⇒ Boolean

Check if a format is supported

Parameters:

  • format (Symbol, String)

    Format name

Returns:

  • (Boolean)


47
48
49
# File 'lib/solid_agent/agent_manifest/exporter_registry.rb', line 47

def supports?(format)
  exporters.key?(format.to_sym)
end