Class: Metanorma::Registry
- Inherits:
-
Object
- Object
- Metanorma::Registry
- Includes:
- Singleton
- Defined in:
- lib/metanorma/registry/registry.rb
Overview
Central registry for managing Metanorma processors, flavors, and their aliases
This singleton class provides a centralized registry for:
-
Metanorma processors (document format processors)
-
Flavor aliases (mapping legacy/alternative names to canonical flavors)
-
Taste configurations (via TasteRegister integration)
The registry maintains backward compatibility with legacy flavor names while integrating with the modern TasteRegister system for dynamic taste management.
Constant Summary collapse
- DEFAULT_ALIASES =
Default legacy aliases for backward compatibility Maps old flavor names to their canonical equivalents
{ csd: :cc, m3d: :m3aawg, mpfd: :mpfa, csand: :csa }.freeze
Instance Attribute Summary collapse
-
#processors ⇒ Object
readonly
Returns the value of attribute processors.
-
#tastes ⇒ Object
readonly
Returns the value of attribute tastes.
Instance Method Summary collapse
-
#alias(flavour) ⇒ Symbol?
Look up the canonical flavor name for a given alias.
-
#find_processor(short) ⇒ Metanorma::Processor?
Find a registered processor by its short name.
-
#initialize ⇒ Registry
constructor
Initialize the registry with processors, tastes, and aliases.
-
#output_formats ⇒ Hash<Symbol, Hash>
Get output formats supported by each registered processor.
-
#register(processor) ⇒ Array<Symbol>
Register a Metanorma processor.
-
#register_alias(alias_name, target_flavor) ⇒ Object
Register a custom alias mapping.
-
#root_tags ⇒ Hash<Symbol, String>
Get XML root tags for processors with Asciidoctor backends.
-
#supported_backends ⇒ Array<Symbol>
Get list of all supported backend names.
Constructor Details
#initialize ⇒ Registry
Initialize the registry with processors, tastes, and aliases
Sets up the registry by:
-
Initializing empty processors hash
-
Connecting to the TasteRegister instance
-
Initializing custom aliases with defaults
51 52 53 54 55 |
# File 'lib/metanorma/registry/registry.rb', line 51 def initialize @processors = {} @tastes = Metanorma::TasteRegister.instance @custom_aliases = DEFAULT_ALIASES.dup end |
Instance Attribute Details
#processors ⇒ Object (readonly)
Returns the value of attribute processors.
39 40 41 |
# File 'lib/metanorma/registry/registry.rb', line 39 def processors @processors end |
#tastes ⇒ Object (readonly)
Returns the value of attribute tastes.
39 40 41 |
# File 'lib/metanorma/registry/registry.rb', line 39 def tastes @tastes end |
Instance Method Details
#alias(flavour) ⇒ Symbol?
Look up the canonical flavor name for a given alias
Checks aliases in priority order:
-
Custom registered aliases (highest priority)
-
Taste-based aliases from TasteRegister
-
Returns nil if no alias found
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/metanorma/registry/registry.rb', line 72 def alias(flavour) return nil if flavour.nil? flavour_sym = flavour.to_sym # Check custom aliases first (includes defaults) return @custom_aliases[flavour_sym] if @custom_aliases.key?(flavour_sym) # Then check taste aliases taste_aliases = @tastes.aliases taste_aliases[flavour_sym] end |
#find_processor(short) ⇒ Metanorma::Processor?
Find a registered processor by its short name
143 144 145 |
# File 'lib/metanorma/registry/registry.rb', line 143 def find_processor(short) @processors[short.to_sym] end |
#output_formats ⇒ Hash<Symbol, Hash>
Get output formats supported by each registered processor
164 165 166 167 168 169 |
# File 'lib/metanorma/registry/registry.rb', line 164 def output_formats @processors.inject({}) do |acc, (k, v)| acc[k] = v.output_formats acc end end |
#register(processor) ⇒ Array<Symbol>
Register a Metanorma processor
Registers a processor class and automatically creates aliases for all its short names. The last short name is considered the canonical name.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/metanorma/registry/registry.rb', line 115 def register(processor) unless processor < ::Metanorma::Processor raise Error, "Processor must inherit from Metanorma::Processor" end # The last short name is the canonical name processor_instance = processor.new short_names = Array(processor_instance.short) canonical_name = short_names.last # Register processor with canonical name @processors[canonical_name] = processor_instance # Create aliases for all short names pointing to canonical name short_names.each { |name| @custom_aliases[name] = canonical_name } Util.log("[metanorma] processor \"#{short_names.first}\" registered", :info) short_names end |
#register_alias(alias_name, target_flavor) ⇒ Object
Register a custom alias mapping
Allows runtime registration of flavor aliases. Custom aliases take precedence over taste-based aliases, allowing overrides of taste configurations.
99 100 101 |
# File 'lib/metanorma/registry/registry.rb', line 99 def register_alias(alias_name, target_flavor) @custom_aliases[alias_name.to_sym] = target_flavor.to_sym end |
#root_tags ⇒ Hash<Symbol, String>
Get XML root tags for processors with Asciidoctor backends
178 179 180 181 182 183 184 185 186 |
# File 'lib/metanorma/registry/registry.rb', line 178 def @processors.inject({}) do |acc, (k, v)| if v.asciidoctor_backend x = Asciidoctor.load nil, { backend: v.asciidoctor_backend } acc[k] = x.converter.xml_root_tag end acc end end |
#supported_backends ⇒ Array<Symbol>
Get list of all supported backend names
153 154 155 |
# File 'lib/metanorma/registry/registry.rb', line 153 def supported_backends @processors.keys end |