Class: SolidAgent::AgentManifest::ParserRegistry
- Inherits:
-
Object
- Object
- SolidAgent::AgentManifest::ParserRegistry
- Defined in:
- lib/solid_agent/agent_manifest/parser_registry.rb
Overview
ParserRegistry manages format parsers and provides format detection.
It enables automatic detection of file formats and routes parsing to the appropriate parser class.
Class Method Summary collapse
-
.detect_format(path) ⇒ Symbol
Detect format from file path.
-
.format_supported?(format) ⇒ Boolean
Check if a format is supported.
-
.formats ⇒ Array<Symbol>
Alias for registered_formats.
-
.parse(path, format: nil) ⇒ Manifest
Parse a file, auto-detecting format if not specified.
-
.parse_string(content, format:) ⇒ Manifest
Parse content string with explicit format.
-
.parser_for(format) ⇒ Class
Get parser for a format.
-
.parsers ⇒ Hash{Symbol => Class}
Registered parsers by format.
-
.register(format, parser_class) ⇒ Object
Register a parser for a format.
-
.registered_formats ⇒ Array<Symbol>
List all registered formats.
-
.supports?(format) ⇒ Boolean
Alias for format_supported?.
Class Method Details
.detect_format(path) ⇒ Symbol
Detect format from file path
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/solid_agent/agent_manifest/parser_registry.rb', line 48 def detect_format(path) extension = File.extname(path).downcase case extension when ".md" detect_markdown_format(path) when ".prompt" :dotprompt when ".yaml", ".yml" detect_yaml_format(path) when ".json" detect_json_format(path) else raise UnknownFormatError, "Cannot detect format for extension: #{extension}" end end |
.format_supported?(format) ⇒ Boolean
Check if a format is supported
101 102 103 |
# File 'lib/solid_agent/agent_manifest/parser_registry.rb', line 101 def format_supported?(format) parsers.key?(format.to_sym) end |
.formats ⇒ Array<Symbol>
Alias for registered_formats
93 94 95 |
# File 'lib/solid_agent/agent_manifest/parser_registry.rb', line 93 def formats registered_formats end |
.parse(path, format: nil) ⇒ Manifest
Parse a file, auto-detecting format if not specified
70 71 72 73 |
# File 'lib/solid_agent/agent_manifest/parser_registry.rb', line 70 def parse(path, format: nil) format ||= detect_format(path) parser_for(format).parse(path) end |
.parse_string(content, format:) ⇒ Manifest
Parse content string with explicit format
80 81 82 |
# File 'lib/solid_agent/agent_manifest/parser_registry.rb', line 80 def parse_string(content, format:) parser_for(format).parse_string(content) end |
.parser_for(format) ⇒ Class
Get parser for a format
39 40 41 |
# File 'lib/solid_agent/agent_manifest/parser_registry.rb', line 39 def parser_for(format) parsers[format.to_sym] || raise(UnknownFormatError, "No parser registered for format: #{format}") end |
.parsers ⇒ Hash{Symbol => Class}
Registered parsers by format
22 23 24 |
# File 'lib/solid_agent/agent_manifest/parser_registry.rb', line 22 def parsers @parsers ||= {} end |
.register(format, parser_class) ⇒ Object
Register a parser for a format
30 31 32 |
# File 'lib/solid_agent/agent_manifest/parser_registry.rb', line 30 def register(format, parser_class) parsers[format.to_sym] = parser_class end |
.registered_formats ⇒ Array<Symbol>
List all registered formats
87 88 89 |
# File 'lib/solid_agent/agent_manifest/parser_registry.rb', line 87 def registered_formats parsers.keys end |
.supports?(format) ⇒ Boolean
Alias for format_supported?
107 108 109 |
# File 'lib/solid_agent/agent_manifest/parser_registry.rb', line 107 def supports?(format) format_supported?(format) end |