Module: Lutaml::Model::RenderPolicy

Overview

Shared render policy mixin for determining what values to skip/render.

Used by both Xml::Transformation and KeyValue::Transformation to provide consistent behavior across serialization formats.

All render/skip decisions are made through the value_map, which is the single source of truth. The user-facing render_nil/render_empty DSL options are normalized into value_map entries at MappingRule construction time, so downstream code never needs to re-interpret them.

Constant Summary collapse

SKIP_PLANS =

Isolated holder: host transformations freeze after compile; an ivar cache on them raises FrozenError (learned the hard way).

::Class.new do
  def self.cache
    @cache ||= {}.compare_by_identity
  end
end.cache

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.derived_attribute_for?(context_obj, attr_name) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
# File 'lib/lutaml/model/render_policy.rb', line 23

def self.derived_attribute_for?(context_obj, attr_name)
  return false unless context_obj.is_a?(Lutaml::Model::Serialize) &&
    context_obj.class.is_a?(Class) &&
    context_obj.class.include?(Lutaml::Model::Serialize)

  register = context_obj.lutaml_register
  context_obj.class.attributes(register)&.[](attr_name)&.derived?
end

Instance Method Details

#should_skip_delegated_value?(value, rule, delegate_obj) ⇒ Boolean

Check if delegated value should be skipped

Parameters:

  • value (Object) —

    The value to check

  • rule (CompiledRule, MappingRule) —

    The rule

  • delegate_obj (Object) —

    The delegated object instance

Returns:

  • (Boolean) —

    true if should skip



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

def should_skip_delegated_value?(value, rule, delegate_obj)
  return true if delegate_obj.nil?

  check_skip_logic?(value, rule, delegate_obj)
end

#should_skip_value?(value, rule, model_instance) ⇒ Boolean

Check if value should be skipped based on render options

Parameters:

  • value (Object) —

    The value to check

  • rule (CompiledRule, MappingRule) —

    The rule

  • model_instance (Object) —

    The model instance

Returns:

  • (Boolean) —

    true if should skip



38
39
40
# File 'lib/lutaml/model/render_policy.rb', line 38

def should_skip_value?(value, rule, model_instance)
  check_skip_logic?(value, rule, model_instance)
end