Class: Lutaml::Model::Schema::XmlCompiler::ComplexType
- Inherits:
-
Object
- Object
- Lutaml::Model::Schema::XmlCompiler::ComplexType
- Defined in:
- lib/lutaml/model/schema/xml_compiler/complex_type.rb
Constant Summary collapse
- SERIALIZABLE_BASE_CLASS =
"Lutaml::Model::Serializable".freeze
- SIMPLE_CONTENT_ATTRIBUTE_TEMPLATE =
ERB.new(<<~TEMPLATE, trim_mode: "-") <%= @indent %>attribute :content, :<%= simple_content_type %><%= ", collection: true" if mixed && !simple_content? %> <%= simple_content.to_attributes(@indent) if simple_content? -%> TEMPLATE
- TEMPLATE =
ERB.new(<<~TEMPLATE, trim_mode: "-") # frozen_string_literal: true require "lutaml/model" <%= required_files.uniq.join("\n") + "\n" -%> <%= module_opening -%> class <%= Utils.camel_case(name) %> < <%= base_class_name %> <%= instances.flat_map { |instance| instance.to_attributes(@indent) }.join + "\n" -%> <%= simple_content_attribute -%> <%= @indent %>xml do <%= extended_indent %>element "<%= name %>" <%= extended_indent %><%= mixed_content? %> <%= namespace_and_prefix %> <%= "\#{extended_indent}map_content to: :content" if simple_content? || mixed %> <%= instances.flat_map { |instance| instance.to_xml_mapping(extended_indent) }.join -%> <%= simple_content.to_xml_mapping(extended_indent) if simple_content? -%> <%= @indent %>end <%= registration_methods -%> end <%= module_closing -%> <%= registration_execution -%> TEMPLATE
Instance Attribute Summary collapse
-
#base_class ⇒ Object
Returns the value of attribute base_class.
-
#id ⇒ Object
Returns the value of attribute id.
-
#instances ⇒ Object
Returns the value of attribute instances.
-
#mixed ⇒ Object
Returns the value of attribute mixed.
-
#name ⇒ Object
Returns the value of attribute name.
-
#simple_content ⇒ Object
Returns the value of attribute simple_content.
Instance Method Summary collapse
- #<<(instance) ⇒ Object
-
#initialize(base_class: SERIALIZABLE_BASE_CLASS) ⇒ ComplexType
constructor
A new instance of ComplexType.
- #required_files ⇒ Object
- #simple_content? ⇒ Boolean
- #to_class(options: {}) ⇒ Object
Constructor Details
#initialize(base_class: SERIALIZABLE_BASE_CLASS) ⇒ ComplexType
Returns a new instance of ComplexType.
43 44 45 46 47 |
# File 'lib/lutaml/model/schema/xml_compiler/complex_type.rb', line 43 def initialize(base_class: SERIALIZABLE_BASE_CLASS) @base_class = base_class @instances = [] @module_namespace = nil end |
Instance Attribute Details
#base_class ⇒ Object
Returns the value of attribute base_class.
6 7 8 |
# File 'lib/lutaml/model/schema/xml_compiler/complex_type.rb', line 6 def base_class @base_class end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/lutaml/model/schema/xml_compiler/complex_type.rb', line 6 def id @id end |
#instances ⇒ Object
Returns the value of attribute instances.
6 7 8 |
# File 'lib/lutaml/model/schema/xml_compiler/complex_type.rb', line 6 def instances @instances end |
#mixed ⇒ Object
Returns the value of attribute mixed.
6 7 8 |
# File 'lib/lutaml/model/schema/xml_compiler/complex_type.rb', line 6 def mixed @mixed end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/lutaml/model/schema/xml_compiler/complex_type.rb', line 6 def name @name end |
#simple_content ⇒ Object
Returns the value of attribute simple_content.
6 7 8 |
# File 'lib/lutaml/model/schema/xml_compiler/complex_type.rb', line 6 def simple_content @simple_content end |
Instance Method Details
#<<(instance) ⇒ Object
49 50 51 52 53 |
# File 'lib/lutaml/model/schema/xml_compiler/complex_type.rb', line 49 def <<(instance) return if instance.nil? @instances << instance end |
#required_files ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/lutaml/model/schema/xml_compiler/complex_type.rb', line 64 def required_files files = [] # Only include external gem requires, not schema class requires # Schema class dependencies are handled via autoload registry unless @module_namespace files.concat(@instances.map(&:required_files).flatten.compact.uniq) files.concat(simple_content.required_files) if simple_content? end files end |
#simple_content? ⇒ Boolean
55 56 57 |
# File 'lib/lutaml/model/schema/xml_compiler/complex_type.rb', line 55 def simple_content? Utils.present?(@simple_content) end |
#to_class(options: {}) ⇒ Object
59 60 61 62 |
# File 'lib/lutaml/model/schema/xml_compiler/complex_type.rb', line 59 def to_class(options: {}) () TEMPLATE.result(binding) end |