Class: Metanorma::TasteRegister
- Inherits:
-
Object
- Object
- Metanorma::TasteRegister
- Includes:
- Singleton
- Defined in:
- lib/metanorma/taste_register.rb
Overview
Registry for managing and providing access to taste configurations
This singleton class automatically discovers taste configurations from the data directory, loads them using lutaml-model, and provides a centralized registry for accessing taste instances and their metadata.
Defined Under Namespace
Classes: InvalidTasteConfigError, UnknownTasteError
Class Method Summary collapse
-
.aliases ⇒ Hash<Symbol, Symbol>
Get flavor aliases mapping.
-
.get(flavor) ⇒ Taste::Base
Get a taste instance by flavor name.
-
.get_config(flavor) ⇒ TasteConfig?
Get detailed information about a specific taste.
Instance Method Summary collapse
- #aliases ⇒ Object
-
#available_tastes ⇒ Array<Symbol>
Get list of available taste flavors.
-
#get(flavor) ⇒ Taste::Base
Get a taste instance by flavor name.
- #get_config(flavor) ⇒ Object
-
#initialize ⇒ TasteRegister
constructor
A new instance of TasteRegister.
Constructor Details
#initialize ⇒ TasteRegister
Returns a new instance of TasteRegister.
35 36 37 38 39 |
# File 'lib/metanorma/taste_register.rb', line 35 def initialize @taste_configs = {} @taste_instances = {} discover_and_load_tastes end |
Class Method Details
.aliases ⇒ Hash<Symbol, Symbol>
Get flavor aliases mapping
110 111 112 |
# File 'lib/metanorma/taste_register.rb', line 110 def self.aliases instance.aliases end |
.get(flavor) ⇒ Taste::Base
Get a taste instance by flavor name
50 51 52 |
# File 'lib/metanorma/taste_register.rb', line 50 def self.get(flavor) instance.get(flavor) end |
.get_config(flavor) ⇒ TasteConfig?
Get detailed information about a specific taste
89 90 91 |
# File 'lib/metanorma/taste_register.rb', line 89 def self.get_config(flavor) instance.get_config(flavor) end |
Instance Method Details
#aliases ⇒ Object
114 115 116 117 118 |
# File 'lib/metanorma/taste_register.rb', line 114 def aliases @taste_configs.each_with_object({}) do |(flavor, config), aliases| aliases[flavor] = config.base_flavor&.to_sym if config.base_flavor end end |
#available_tastes ⇒ Array<Symbol>
Get list of available taste flavors
77 78 79 |
# File 'lib/metanorma/taste_register.rb', line 77 def available_tastes @taste_configs.keys end |
#get(flavor) ⇒ Taste::Base
Get a taste instance by flavor name
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/metanorma/taste_register.rb', line 59 def get(flavor) flavor_sym = normalize_flavor_name(flavor) return @taste_instances[flavor_sym] if @taste_instances[flavor_sym] config = @taste_configs[flavor_sym] raise UnknownTasteError, "Unknown taste: #{flavor}" unless config @taste_instances[flavor_sym] = create_taste_instance(flavor_sym, config) end |
#get_config(flavor) ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/metanorma/taste_register.rb', line 93 def get_config(flavor) flavor_sym = normalize_flavor_name(flavor) config = @taste_configs[flavor_sym] return nil unless config # Set the directory on the config object config.directory = config_directory_for(flavor_sym) config end |