Class: Lutaml::Model::Schema::XmlCompiler::Group
- Inherits:
-
Object
- Object
- Lutaml::Model::Schema::XmlCompiler::Group
- Defined in:
- lib/lutaml/model/schema/xml_compiler/group.rb
Constant Summary collapse
- GROUP_TEMPLATE =
ERB.new("# frozen_string_literal: true\n\n<%= \"\\n\" + required_files.uniq.join(\"\\n\") -%>\n\nclass <%= Utils.camel_case(base_name) %> < Lutaml::Model::Serializable\n<%= definitions_content %>\n<%= xml_mapping_block -%>\n\n<%= @indent %>def self.register\n<%= extended_indent %>@register ||= 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(base_name) %>)\n<%= @indent %>end\nend\n\n<%= Utils.camel_case(base_name) %>.register_class_with_id\n", trim_mode: "-")
- XML_MAPPING_TEMPLATE =
ERB.new("<%= @indent %>xml do\n<%= extended_indent %>no_root\n<%= instance&.to_xml_mapping(extended_indent) -%>\n<%= @indent %>end\n", trim_mode: "-")
Instance Attribute Summary collapse
-
#instance ⇒ Object
Returns the value of attribute instance.
-
#name ⇒ Object
Returns the value of attribute name.
-
#ref ⇒ Object
Returns the value of attribute ref.
Instance Method Summary collapse
- #base_name ⇒ Object
-
#initialize(name = nil, ref = nil) ⇒ Group
constructor
A new instance of Group.
- #required_files ⇒ Object
- #to_attributes(indent = @indent) ⇒ Object
- #to_class(options: {}) ⇒ Object
- #to_xml_mapping(indent = @indent) ⇒ Object
Constructor Details
#initialize(name = nil, ref = nil) ⇒ Group
Returns a new instance of Group.
38 39 40 41 |
# File 'lib/lutaml/model/schema/xml_compiler/group.rb', line 38 def initialize(name = nil, ref = nil) @name = name @ref = ref end |
Instance Attribute Details
#instance ⇒ Object
Returns the value of attribute instance.
8 9 10 |
# File 'lib/lutaml/model/schema/xml_compiler/group.rb', line 8 def instance @instance end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/lutaml/model/schema/xml_compiler/group.rb', line 8 def name @name end |
#ref ⇒ Object
Returns the value of attribute ref.
8 9 10 |
# File 'lib/lutaml/model/schema/xml_compiler/group.rb', line 8 def ref @ref end |
Instance Method Details
#base_name ⇒ Object
72 73 74 |
# File 'lib/lutaml/model/schema/xml_compiler/group.rb', line 72 def base_name (name || ref)&.split(":")&.last end |
#required_files ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/lutaml/model/schema/xml_compiler/group.rb', line 56 def required_files if Utils.blank?(name) && Utils.present?(ref) "require_relative \"#{Utils.snake_case(ref.split(':').last)}\"" else @instance&.required_files end end |
#to_attributes(indent = @indent) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/lutaml/model/schema/xml_compiler/group.rb', line 64 def to_attributes(indent = @indent) if Utils.present?(@ref) "#{indent}import_model_attributes :#{Utils.snake_case(base_name)}\n" else @instance.to_attributes(indent) end end |
#to_class(options: {}) ⇒ Object
51 52 53 54 |
# File 'lib/lutaml/model/schema/xml_compiler/group.rb', line 51 def to_class(options: {}) () GROUP_TEMPLATE.result(binding) end |
#to_xml_mapping(indent = @indent) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/lutaml/model/schema/xml_compiler/group.rb', line 43 def to_xml_mapping(indent = @indent) if Utils.present?(@ref) "#{indent}import_model_mappings :#{Utils.snake_case(base_name)}\n" else @instance.to_xml_mapping(indent * 2) end end |