Module: Lutaml::Xml::PlanHydrator
- Defined in:
- lib/lutaml/xml/plan_hydrator.rb
Overview
Hydrates model instances from a Descriptor#walk PlanValue tree, keyed by each value's producing row name (never position — rows for missing elements are simply absent). Native rows build constructor kwargs; deferred rows (custom methods, polymorphism, unions) capture their subtree verbatim and interpret it post-walk — the fragment parse runs the existing interpretive machinery on just that island. Delegate rules hydrate post-instance onto their target object. Collection rows route natively when a single one exists, else through callback rows (their values echo name and type_tag; native collection values echo neither — leptris-ruby#220).
Class Method Summary collapse
-
.call(model_class, plan, value, parent: nil, node: nil) ⇒ Object
plan: the compiler's entry for model_class value: the walk root PlanValue (element) node: the parsed source element (leptris); ordered/mixed plans rebuild element_order from it and ordered children hydrate natively against their own nodes.
Class Method Details
.call(model_class, plan, value, parent: nil, node: nil) ⇒ Object
plan: the compiler's entry for model_class value: the walk root PlanValue (element) node: the parsed source element (leptris); ordered/mixed plans rebuild element_order from it and ordered children hydrate natively against their own nodes
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lutaml/xml/plan_hydrator.rb', line 23 def call(model_class, plan, value, parent: nil, node: nil) buckets = node && plan[:needs_nodes] ? element_buckets(node) : nil attr_kwargs = attributes_kwargs(plan, value) child_kwargs, children, delegates = children_kwargs(model_class, plan, value, buckets) plan[:collection_defaults].each do |name| next if attr_kwargs.key?(name) || child_kwargs.key?(name) child_kwargs[name] = [] end instance = model_class.new(**attr_kwargs, **child_kwargs) instance.lutaml_parent = parent if parent instance.lutaml_root ||= parent&.lutaml_root || parent instance.element_order = PlanOrder.build(node) if node && plan[:ordered] children.each do |child| child.lutaml_parent = instance child.lutaml_root ||= instance.lutaml_root || instance end interpret_deferred(model_class, plan, value, instance, node, buckets) route_delegates(delegates, instance) instance end |