Module: Dcc::ContextConfiguration
- Included in:
- Si::V1::Configuration, Si::V2::Configuration, V2::Configuration, V3::Configuration
- Defined in:
- lib/dcc/context_configuration.rb
Instance Attribute Summary collapse
-
#default_context_id ⇒ Symbol
The context id used when none is supplied explicitly.
Instance Method Summary collapse
-
#clear_custom_models ⇒ Object
Reset any custom default context.
-
#context ⇒ Lutaml::Model::Context?
The live context for this version, or
nilif not yet populated. -
#context_id ⇒ Symbol
The version's canonical context id (e.g.
:dcc_v3). -
#create_context(id:, registry: nil, fallback_to: [context_id], substitutions: []) ⇒ Object
Create or replace a context.
-
#custom_models=(models) ⇒ Object
Convenience: bulk-register model substitutions.
-
#fallback_contexts ⇒ Array<Symbol>
Contexts that this one falls back to when type lookup fails.
-
#populate_context! ⇒ Object
Rebuild the version's built-in context from
registered_models. -
#register_model(klass, id:) ⇒ Class
Register a model for an XML element name and remember it for rebuilds.
-
#registered_model_class(id) ⇒ Class?
The registered class.
-
#registered_model_ids ⇒ Array<Symbol>
Public read-only accessors for cross-context re-export.
Instance Attribute Details
#default_context_id ⇒ Symbol
Returns the context id used when none is supplied explicitly.
78 79 80 |
# File 'lib/dcc/context_configuration.rb', line 78 def default_context_id @default_context_id || context_id end |
Instance Method Details
#clear_custom_models ⇒ Object
Reset any custom default context.
97 98 99 |
# File 'lib/dcc/context_configuration.rb', line 97 def clear_custom_models @default_context_id = nil end |
#context ⇒ Lutaml::Model::Context?
Returns the live context for this version,
or nil if not yet populated.
26 27 28 |
# File 'lib/dcc/context_configuration.rb', line 26 def context Lutaml::Model::GlobalContext.context(context_id) end |
#context_id ⇒ Symbol
Returns the version's canonical context id (e.g. :dcc_v3).
20 21 22 |
# File 'lib/dcc/context_configuration.rb', line 20 def context_id self::CONTEXT_ID end |
#create_context(id:, registry: nil, fallback_to: [context_id], substitutions: []) ⇒ Object
Create or replace a context. If id matches the version's canonical
context id, the built-in context is rebuilt via populate_context!.
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dcc/context_configuration.rb', line 37 def create_context(id:, registry: nil, fallback_to: [context_id], substitutions: []) normalized_id = ::Dcc::ContextOptions.normalize_context_reference(id) return populate_context! if normalized_id == context_id unregister_existing(normalized_id) create_type_context( id: normalized_id, registry: registry || Lutaml::Model::TypeRegistry.new, fallback_to: normalize_fallbacks(fallback_to), substitutions: substitutions, ) end |
#custom_models=(models) ⇒ Object
Convenience: bulk-register model substitutions.
88 89 90 91 92 93 94 |
# File 'lib/dcc/context_configuration.rb', line 88 def custom_models=(models) substitutions = models.map do |from_type, to_type| { from_type: from_type, to_type: to_type } end create_context(id: :custom_models, substitutions: substitutions) @default_context_id = :custom_models end |
#fallback_contexts ⇒ Array<Symbol>
Contexts that this one falls back to when type lookup fails.
Override in version modules to pull in cross-namespace types
(e.g. DCC contexts fall back to D-SI contexts for :real, :hybrid).
60 61 62 |
# File 'lib/dcc/context_configuration.rb', line 60 def fallback_contexts [:default] end |
#populate_context! ⇒ Object
Rebuild the version's built-in context from registered_models.
51 52 53 54 |
# File 'lib/dcc/context_configuration.rb', line 51 def populate_context! unregister_existing(context_id) register_models_in(base_type_context) end |
#register_model(klass, id:) ⇒ Class
Register a model for an XML element name and remember it for rebuilds.
69 70 71 72 73 74 75 |
# File 'lib/dcc/context_configuration.rb', line 69 def register_model(klass, id:) normalized_id = id.to_sym registered_models[normalized_id] = klass (context || populate_base_context).registry.register(normalized_id, klass) clear_cache(klass) klass end |
#registered_model_class(id) ⇒ Class?
Returns the registered class.
109 110 111 |
# File 'lib/dcc/context_configuration.rb', line 109 def registered_model_class(id) registered_models[id.to_sym] end |
#registered_model_ids ⇒ Array<Symbol>
Public read-only accessors for cross-context re-export.
103 104 105 |
# File 'lib/dcc/context_configuration.rb', line 103 def registered_model_ids registered_models.keys end |