Class: SolidAgent::AgentManifest::ExporterRegistry
- Inherits:
-
Object
- Object
- SolidAgent::AgentManifest::ExporterRegistry
- Defined in:
- lib/solid_agent/agent_manifest/exporter_registry.rb
Overview
ExporterRegistry manages format exporters for converting Manifests to various formats.
Class Method Summary collapse
-
.convert(input_path, output_format, output_path = nil) ⇒ String
Convert between formats.
-
.export(manifest, format, **options) ⇒ String
Export a manifest to a format string.
-
.export_to_file(manifest, format, path, **options) ⇒ String
Export a manifest to a file.
-
.exporter_for(format) ⇒ Class
Get the exporter for a format.
-
.exporters ⇒ Hash<Symbol, Class>
Registered exporters by format name.
-
.formats ⇒ Array<Symbol>
List all registered format names.
-
.register(format, exporter_class) ⇒ Object
Register an exporter for a format.
-
.supports?(format) ⇒ Boolean
Check if a format is supported.
Class Method Details
.convert(input_path, output_format, output_path = nil) ⇒ String
Convert between formats
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
64 65 66 67 |
# File 'lib/solid_agent/agent_manifest/exporter_registry.rb', line 64 def export(manifest, format, **) exporter = exporter_for(format) exporter.export(manifest, **) end |
.export_to_file(manifest, format, path, **options) ⇒ String
Export a manifest to a file
76 77 78 79 80 |
# File 'lib/solid_agent/agent_manifest/exporter_registry.rb', line 76 def export_to_file(manifest, format, path, **) content = export(manifest, format, **) File.write(path, content, encoding: "UTF-8") path end |
.exporter_for(format) ⇒ Class
Get the exporter for a format
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 |
.exporters ⇒ Hash<Symbol, Class>
Registered exporters by format name
21 22 23 |
# File 'lib/solid_agent/agent_manifest/exporter_registry.rb', line 21 def exporters @exporters ||= {} end |
.formats ⇒ Array<Symbol>
List all registered format names
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
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
47 48 49 |
# File 'lib/solid_agent/agent_manifest/exporter_registry.rb', line 47 def supports?(format) exporters.key?(format.to_sym) end |