Class: Lutaml::Model::TransformationBuilder Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/model/transformation_builder.rb

Overview

This class is abstract.

Subclasses must implement TransformationBuilder.build

Abstract base class for transformation builders.

Implements the Builder Pattern for creating format-specific transformations. This satisfies the Open/Closed Principle: open for extension, closed for modification.

To add a new serialization format:

  1. Create a subclass of TransformationBuilder

  2. Implement the ‘build` class method

  3. Register with TransformationRegistry.register_builder(format, builder)

Examples:

Creating a custom builder

class ProtobufTransformationBuilder < TransformationBuilder
  def self.build(model_class, mapping, format, register)
    Protobuf::Transformation.new(model_class, mapping, format, register)
  end
end

TransformationRegistry.register_builder(:protobuf, ProtobufTransformationBuilder)

Class Method Summary collapse

Class Method Details

.build(model_class, mapping, format, register) ⇒ Transformation

This method is abstract.

Subclasses must implement this method

Build a transformation instance for the given format.

Parameters:

  • model_class (Class)

    The model class

  • mapping (Mapping)

    The resolved mapping

  • format (Symbol)

    The format symbol

  • register (Register, nil)

    The register for type resolution

Returns:

Raises:

  • (NotImplementedError)

    if not implemented by subclass



36
37
38
39
# File 'lib/lutaml/model/transformation_builder.rb', line 36

def self.build(model_class, mapping, format, register)
  raise NotImplementedError,
        "#{self.class}.build must be implemented"
end

.handles?(format) ⇒ Boolean

Check if this builder can handle the given format.

Default implementation checks the FORMATS constant. Subclasses can override for more complex logic.

Parameters:

  • format (Symbol)

    The format to check

Returns:

  • (Boolean)

    true if this builder handles the format



48
49
50
51
52
# File 'lib/lutaml/model/transformation_builder.rb', line 48

def self.handles?(format)
  return false unless const_defined?(:FORMATS, false)

  const_get(:FORMATS, false).include?(format)
end