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.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.derived_attribute_for?(context_obj, attr_name) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
# File 'lib/lutaml/model/render_policy.rb', line 15

def self.derived_attribute_for?(context_obj, attr_name)
  return false unless context_obj&.class.respond_to?(:attributes)

  register = context_obj.respond_to?(:lutaml_register) ? context_obj.lutaml_register : nil
  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



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

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



28
29
30
# File 'lib/lutaml/model/render_policy.rb', line 28

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