Class: Lutaml::Model::Schema::XmlCompiler::ComplexType

Inherits:
Object
  • Object
show all
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("<%= @indent %>attribute :content, :<%= simple_content_type %>\n<%= simple_content.to_attributes(@indent) if simple_content? -%>\n", trim_mode: "-")
TEMPLATE =
ERB.new("# frozen_string_literal: true\n\n<%= required_files.uniq.join(\"\\n\") + \"\\n\" -%>\nclass <%= Utils.camel_case(name) %> < <%= base_class_name %>\n<%= instances.flat_map { |instance| instance.to_attributes(@indent) }.join + \"\\n\" -%>\n<%= simple_content_attribute -%>\n<%= @indent %>xml do\n<%= extended_indent %>root \"<%= name %>\"<%= root_options %>\n<%= namespace_and_prefix %>\n<%= \"\\\#{extended_indent}map_content to: :content\" if simple_content? || mixed %>\n<%= instances.flat_map { |instance| instance.to_xml_mapping(extended_indent) }.join -%>\n<%= simple_content.to_xml_mapping(extended_indent) if simple_content? -%>\n<%= @indent %>end\n\n<%= @indent %>def self.register\n<%= extended_indent %>Lutaml::Model::GlobalRegister.lookup(Lutaml::Model::Config.default_register)\n<%= @indent %>end\n\n<%= @indent %>def self.register_class_with_id\n<%= extended_indent %>register.register_model(self, id: :<%= Utils.snake_case(name) %>)\n<%= @indent %>end\nend\n\n<%= Utils.camel_case(name) %>.register_class_with_id\n", trim_mode: "-")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_class: SERIALIZABLE_BASE_CLASS) ⇒ 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_classObject

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

#idObject

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

#instancesObject

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

#mixedObject

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

#nameObject

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_contentObject

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_filesObject



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: {})
  setup_options(options)
  TEMPLATE.result(binding)
end