Module: Lutaml::Model::Schema::Templates

Defined in:
lib/lutaml/model/schema/templates.rb

Overview

Templates that are actually shared between schema compilers (XSD, RNG, future formats). Single-consumer templates live in the renderer that uses them — putting them here would just be relocation, not deduplication.

Each constant is an ERB.new(...) evaluated via TEMPLATE.result(binding) from a renderer that exposes the required hook methods (documented above each template).

Constant Summary collapse

SERIALIZABLE_CLASS =

Single shape for any Lutaml::Model::Serializable subclass generated by ANY schema compiler. There is no per-format variant — adding a new xml directive here propagates to every compiler that uses this template. Consumed by:

- Lutaml::Model::Schema::Renderers::Model
(renders XSD complex types / groups and RNG generated classes)

Required binding methods (renderer must expose all of these, returning "" / nil / false for inapplicable sections):

from ClassBoilerplate:
module_opening, module_closing,
registration_methods, registration_execution,
boilerplate_indent_str

identity / parent:
rendered_class_name                 String 

ERB.new("# frozen_string_literal: true\n\nrequire \"lutaml/model\"\n<%= serializable_class_required_files -%>\n<%= module_opening -%>\n<%= serializable_class_documentation -%>\nclass <%= rendered_class_name %> < <%= serializable_class_parent %>\n<%= serializable_class_attributes -%>\n<%= serializable_class_imports -%>\n<%= \"\\n\" if serializable_class_attributes.length.positive? || serializable_class_imports.length.positive? -%>\n<%= boilerplate_indent_str %>xml do\n<%- if xml_root_directive_line -%>\n<%= boilerplate_indent_str * 2 %><%= xml_root_directive_line %>\n<%- end -%>\n<%- if xml_namespace_line -%>\n<%= boilerplate_indent_str * 2 %><%= xml_namespace_line %>\n<%- end -%>\n<%- if xml_mixed_content? -%>\n<%= boilerplate_indent_str * 2 %>mixed_content\n<%- end -%>\n<%- if xml_text_content? -%>\n<%= boilerplate_indent_str * 2 %>map_content to: :content\n<%- end -%>\n<%= xml_attribute_mappings -%>\n<%= xml_extra_mappings -%>\n<%= boilerplate_indent_str %>end\n<%= registration_methods -%>\nend\n<%= module_closing -%>\n<%= registration_execution -%>\n", trim_mode: "-")
XML_NAMESPACE =

XmlNamespace subclass. Consumed by:

- Lutaml::Model::Schema::Renderers::Namespace

Binding: module_opening, module_closing, class_name, uri, prefix_default.

ERB.new("# frozen_string_literal: true\n\nrequire \"lutaml/model\"\n\n<%= module_opening -%>\n# Namespace: <%= uri %>\nclass <%= class_name %> < Lutaml::Xml::W3c::XmlNamespace\n  uri <%= uri.inspect %>\n  prefix_default <%= prefix_default.inspect %>\n<%- if element_form_default_line -%>\n  <%= element_form_default_line %>\n<%- end -%>\nend\n<%= module_closing -%>\n", trim_mode: "-")
RESTRICTED_SIMPLE_TYPE =

Restricted simple-type subclass (cast method that mutates options with facets then delegates to super). Consumed by:

- Lutaml::Model::Schema::Renderers::RestrictedType

Binding: module_opening, module_closing, registration_methods, registration_execution, rendered_class_name, parent_class, xml_namespace_line, restricted_simple_type_required_files, restricted_simple_type_facet_declarations, restricted_simple_type_cast_body, boilerplate_indent_str.

ERB.new("# frozen_string_literal: true\nrequire \"lutaml/model\"\n<%= restricted_simple_type_required_files -%>\n<%= module_opening -%>\nclass <%= rendered_class_name %><%= \" < \\\#{parent_class}\" if parent_class %>\n<%- if xml_namespace_line -%>\n<%= boilerplate_indent_str %>xml do\n<%= boilerplate_indent_str * 2 %><%= xml_namespace_line %>\n<%= boilerplate_indent_str %>end\n<%- end -%>\n<%= restricted_simple_type_facet_declarations -%>\n<%= boilerplate_indent_str %>def self.cast(value, options = {})\n<%= boilerplate_indent_str * 2 %>return if value.nil?\n\n<%= restricted_simple_type_cast_body -%>\n<%= boilerplate_indent_str * 2 %>value = super(value, options)\n<%= boilerplate_indent_str * 2 %>value\n<%= boilerplate_indent_str %>end\n<%= registration_methods -%>\nend\n<%= module_closing -%>\n<%= registration_execution -%>\n", trim_mode: "-")
UNION_TYPE =

Lutaml::Model::Type::Value union subclass. Consumed by:

- Lutaml::Model::Schema::Renderers::Union

union_cast_body selects the cast strategy from the spec (XSD: ||-chained resolve_type; RNG: each+rescue).

ERB.new("# frozen_string_literal: true\nrequire \"lutaml/model\"\n<%= union_required_files -%>\n<%= module_opening -%>\nclass <%= rendered_class_name %> < Lutaml::Model::Type::Value\n<%= boilerplate_indent_str %>def self.cast(value, options = {})\n<%= boilerplate_indent_str * 2 %>return if value.nil?\n\n<%= union_cast_body -%>\n<%= boilerplate_indent_str %>end\n<%= registration_methods -%>\nend\n<%= module_closing -%>\n<%= registration_execution -%>\n", trim_mode: "-")