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 %> <%= simple_content.to_attributes(@indent) if simple_content? -%> TEMPLATE
- TEMPLATE =
ERB.new(<<~TEMPLATE, trim_mode: "-") # frozen_string_literal: true <%= required_files.uniq.join("\n") + "\n" -%> 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 %>root "<%= name %>"<%= root_options %> <%= 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 <%= @indent %>def self.register <%= extended_indent %>Lutaml::Model::GlobalRegister.lookup(Lutaml::Model::Config.default_register) <%= @indent %>end <%= @indent %>def self.register_class_with_id <%= extended_indent %>register.register_model(self, id: :<%= Utils.snake_case(name) %>) <%= @indent %>end end <%= Utils.camel_case(name) %>.register_class_with_id 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.
47 48 49 50 |
# File 'lib/lutaml/model/schema/xml_compiler/complex_type.rb', line 47 def initialize(base_class: SERIALIZABLE_BASE_CLASS) @base_class = base_class @instances = [] 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
52 53 54 55 56 |
# File 'lib/lutaml/model/schema/xml_compiler/complex_type.rb', line 52 def <<(instance) return if instance.nil? @instances << instance end |
#required_files ⇒ Object
67 68 69 70 71 72 |
# File 'lib/lutaml/model/schema/xml_compiler/complex_type.rb', line 67 def required_files files = [base_class_require] files.concat(@instances.map(&:required_files).flatten.compact.uniq) files.concat(simple_content.required_files) if simple_content? files end |
#simple_content? ⇒ Boolean
58 59 60 |
# File 'lib/lutaml/model/schema/xml_compiler/complex_type.rb', line 58 def simple_content? Utils.present?(@simple_content) end |
#to_class(options: {}) ⇒ Object
62 63 64 65 |
# File 'lib/lutaml/model/schema/xml_compiler/complex_type.rb', line 62 def to_class(options: {}) () TEMPLATE.result(binding) end |