Class: Lutaml::Model::Transformation Abstract
- Inherits:
-
Object
- Object
- Lutaml::Model::Transformation
- Defined in:
- lib/lutaml/model/transformation.rb
Overview
Subclasses must implement #transform and #compile_rules
Abstract base class for format-specific transformations.
A Transformation converts a model instance into a format-specific intermediate representation (like XmlElement) without triggering type resolution or imports during the transformation process.
Transformations are pre-compiled at class definition time and frozen to prevent modifications. They contain all necessary information (compiled rules, namespaces, etc.) for transforming instances.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#compiled_rules ⇒ Array<CompiledRule>
readonly
Pre-compiled transformation rules.
-
#format ⇒ Symbol
readonly
The format (:xml, :json, :yaml, etc.).
-
#model_class ⇒ Class
readonly
The model class this transformation applies to.
-
#register ⇒ Register?
readonly
The register used for type resolution.
Instance Method Summary collapse
-
#after_compile ⇒ Object
Hook for format subclasses to derive rule-set-level data after compilation, before the transformation is frozen and shared.
-
#all_namespaces ⇒ Array<Class>
Collect all namespaces used in this transformation.
-
#initialize(model_class, mapping_dsl, format, register) ⇒ Transformation
constructor
Initialize a new transformation.
-
#transform(model_instance, options = {}) ⇒ Object
abstract
Transform a model instance into format-specific representation.
Constructor Details
#initialize(model_class, mapping_dsl, format, register) ⇒ Transformation
Initialize a new transformation
35 36 37 38 39 40 41 42 |
# File 'lib/lutaml/model/transformation.rb', line 35 def initialize(model_class, mapping_dsl, format, register) @model_class = model_class @format = format @register = register @compiled_rules = compile_rules(mapping_dsl) after_compile freeze end |
Instance Attribute Details
#compiled_rules ⇒ Array<CompiledRule> (readonly)
Returns Pre-compiled transformation rules.
27 28 29 |
# File 'lib/lutaml/model/transformation.rb', line 27 def compiled_rules @compiled_rules end |
#format ⇒ Symbol (readonly)
Returns The format (:xml, :json, :yaml, etc.).
21 22 23 |
# File 'lib/lutaml/model/transformation.rb', line 21 def format @format end |
#model_class ⇒ Class (readonly)
Returns The model class this transformation applies to.
18 19 20 |
# File 'lib/lutaml/model/transformation.rb', line 18 def model_class @model_class end |
#register ⇒ Register? (readonly)
Returns The register used for type resolution.
24 25 26 |
# File 'lib/lutaml/model/transformation.rb', line 24 def register @register end |
Instance Method Details
#after_compile ⇒ Object
Hook for format subclasses to derive rule-set-level data after compilation, before the transformation is frozen and shared.
46 |
# File 'lib/lutaml/model/transformation.rb', line 46 def after_compile; end |
#all_namespaces ⇒ Array<Class>
Collect all namespaces used in this transformation
This method traverses compiled rules recursively to collect all namespace classes, enabling namespace declaration planning without triggering type resolution.
67 68 69 70 71 72 73 |
# File 'lib/lutaml/model/transformation.rb', line 67 def all_namespaces namespaces = [] compiled_rules.each do |rule| namespaces.concat(rule.all_namespaces) end namespaces.uniq end |
#transform(model_instance, options = {}) ⇒ Object
Subclasses must implement this method
Transform a model instance into format-specific representation
55 56 57 58 |
# File 'lib/lutaml/model/transformation.rb', line 55 def transform(model_instance, = {}) raise NotImplementedError, "#{self.class}#transform must be implemented" end |