Class: Lutaml::KeyValue::Transformation::CollectionSerializer
- Inherits:
-
Object
- Object
- Lutaml::KeyValue::Transformation::CollectionSerializer
- Includes:
- Model::RenderPolicy
- Defined in:
- lib/lutaml/key_value/transformation/collection_serializer.rb
Overview
Serializes collections for key-value formats.
This is an independent class with explicit dependencies that can be tested in isolation from Transformation.
Handles:
-
Array collections
-
Keyed collections (map_key feature)
-
Root mappings pattern
-
render_nil and render_empty options
Instance Attribute Summary collapse
-
#format ⇒ Symbol
readonly
The serialization format (:json, :yaml, :toml).
-
#register_id ⇒ Symbol?
readonly
The register ID for attribute lookup.
-
#transformation_factory ⇒ Proc
readonly
Factory lambda for creating child transformations.
-
#value_serializer ⇒ ValueSerializer
readonly
The value serializer for item serialization.
Instance Method Summary collapse
-
#initialize(format:, register_id:, value_serializer:, transformation_factory:) ⇒ CollectionSerializer
constructor
Initialize the CollectionSerializer with explicit dependencies.
-
#keyed_collection_key_attribute(child_mappings) ⇒ Symbol?
Get the key attribute for a keyed collection from child_mappings.
-
#serialize(parent, collection, rule, options = {}, converted_from_empty_to_nil: false, converted_from_nil_to_empty: false) ⇒ void
Serialize a collection to elements.
-
#serialize_array(parent, items, rule, options = {}) ⇒ void
Serialize an array collection.
-
#serialize_keyed(parent, items, rule, key_attribute, child_mappings, options = {}) ⇒ void
Serialize a keyed collection (map_key feature).
Methods included from Model::RenderPolicy
derived_attribute_for?, #should_skip_delegated_value?, #should_skip_value?
Constructor Details
#initialize(format:, register_id:, value_serializer:, transformation_factory:) ⇒ CollectionSerializer
Initialize the CollectionSerializer with explicit dependencies.
38 39 40 41 42 43 44 |
# File 'lib/lutaml/key_value/transformation/collection_serializer.rb', line 38 def initialize(format:, register_id:, value_serializer:, transformation_factory:) @format = format @register_id = register_id @value_serializer = value_serializer @transformation_factory = transformation_factory end |
Instance Attribute Details
#format ⇒ Symbol (readonly)
Returns The serialization format (:json, :yaml, :toml).
21 22 23 |
# File 'lib/lutaml/key_value/transformation/collection_serializer.rb', line 21 def format @format end |
#register_id ⇒ Symbol? (readonly)
Returns The register ID for attribute lookup.
24 25 26 |
# File 'lib/lutaml/key_value/transformation/collection_serializer.rb', line 24 def register_id @register_id end |
#transformation_factory ⇒ Proc (readonly)
Returns Factory lambda for creating child transformations.
30 31 32 |
# File 'lib/lutaml/key_value/transformation/collection_serializer.rb', line 30 def transformation_factory @transformation_factory end |
#value_serializer ⇒ ValueSerializer (readonly)
Returns The value serializer for item serialization.
27 28 29 |
# File 'lib/lutaml/key_value/transformation/collection_serializer.rb', line 27 def value_serializer @value_serializer end |
Instance Method Details
#keyed_collection_key_attribute(child_mappings) ⇒ Symbol?
Get the key attribute for a keyed collection from child_mappings.
95 96 97 98 99 100 101 102 103 |
# File 'lib/lutaml/key_value/transformation/collection_serializer.rb', line 95 def keyed_collection_key_attribute(child_mappings) return nil unless child_mappings child_mappings.each do |attr_name, mapping| return attr_name.to_sym if mapping == :key end nil end |
#serialize(parent, collection, rule, options = {}, converted_from_empty_to_nil: false, converted_from_nil_to_empty: false) ⇒ void
This method returns an undefined value.
Serialize a collection to elements.
This is the main entry point for collection serialization.
57 58 59 60 61 62 63 |
# File 'lib/lutaml/key_value/transformation/collection_serializer.rb', line 57 def serialize(parent, collection, rule, = {}, converted_from_empty_to_nil: false, converted_from_nil_to_empty: false) create_collection_element(parent, collection, rule, , converted_from_empty_to_nil: converted_from_empty_to_nil, converted_from_nil_to_empty: converted_from_nil_to_empty) end |
#serialize_array(parent, items, rule, options = {}) ⇒ void
This method returns an undefined value.
Serialize an array collection.
87 88 89 |
# File 'lib/lutaml/key_value/transformation/collection_serializer.rb', line 87 def serialize_array(parent, items, rule, = {}) create_array_collection_element(parent, rule, items, ) end |
#serialize_keyed(parent, items, rule, key_attribute, child_mappings, options = {}) ⇒ void
This method returns an undefined value.
Serialize a keyed collection (map_key feature).
74 75 76 77 78 |
# File 'lib/lutaml/key_value/transformation/collection_serializer.rb', line 74 def serialize_keyed(parent, items, rule, key_attribute, child_mappings, = {}) create_keyed_collection_element(parent, rule, items, key_attribute, child_mappings, ) end |