Module: Lutaml::Model::Type::UninitializedClassGuard

Included in:
Value
Defined in:
lib/lutaml/model/type/uninitialized_class_guard.rb

Overview

Module that handles UninitializedClass sentinel value.

This module should be prepended to Type::Value so that ALL type subclasses automatically handle UninitializedClass without needing to call super or add explicit checks.

This ensures custom types that override cast() completely still receive the UninitializedClass check automatically.

Instance Method Summary collapse

Instance Method Details

#cast(value, *args, **kwargs) ⇒ Object

Intercept cast to handle UninitializedClass before any subclass-specific logic runs.

The prepend ensures this method runs BEFORE the subclass’s cast implementation, even if the subclass doesn’t call super.



20
21
22
23
24
25
# File 'lib/lutaml/model/type/uninitialized_class_guard.rb', line 20

def cast(value, *args, **kwargs, &)
  # Return UninitializedClass unchanged - don't transform it
  return value if Utils.uninitialized?(value)

  super
end

#serialize(value) ⇒ Object

Also guard serialize for consistency



28
29
30
31
32
# File 'lib/lutaml/model/type/uninitialized_class_guard.rb', line 28

def serialize(value)
  return value if Utils.uninitialized?(value)

  super
end