Module: Omml::Configuration::ModelRegistry
- Included in:
- Omml::Configuration
- Defined in:
- lib/omml/configuration/model_registry.rb
Overview
Extended only by Omml::Configuration together with the sibling modules.
Instance Method Summary collapse
Instance Method Details
#model_id_for(klass) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/omml/configuration/model_registry.rb', line 19 def model_id_for(klass) class_name = klass.name.split("::").last prefix = SCHEMA_MODEL_PREFIXES.find do |candidate| class_name.start_with?(candidate) && class_name != candidate end if prefix model_name = class_name.delete_prefix(prefix) return :"#{prefix.downcase}_#{Lutaml::Model::Utils.snake_case(model_name)}" end Lutaml::Model::Utils.snake_case(class_name).to_sym end |
#register_model(klass, id: nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/omml/configuration/model_registry.rb', line 7 def register_model(klass, id: nil) model_id = (id || model_id_for(klass)).to_sym registered_models[model_id] = klass if (type_context = context(context_id)) type_context.registry.register(model_id, klass) clear_cache(klass, type_context.id) end klass end |
#registered_models ⇒ Object
33 34 35 |
# File 'lib/omml/configuration/model_registry.rb', line 33 def registered_models @registered_models ||= {} end |