Module: Lutaml::Model::Schema::Helpers::TemplateHelper

Included in:
Context
Defined in:
lib/lutaml/model/schema/helpers/template_helper.rb

Instance Method Summary collapse

Instance Method Details

#attribute_line(attribute, level) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lutaml/model/schema/helpers/template_helper.rb', line 18

def attribute_line(attribute, level)
  if attribute.choice?
    "\n      \#{indent(level)}choice do\n      \#{attribute.attributes.map { |attr| attribute_line(attr, level + 1) }.join(\"\\n\")}\n      \#{indent(level)}end\n    RUBY\n  else\n    \"\#{indent(level)}attribute \#{attribute_properties(attribute)}\"\n  end\nend\n".chomp

#attribute_properties(attribute) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/lutaml/model/schema/helpers/template_helper.rb', line 31

def attribute_properties(attribute)
  # properties = {}
  # properties[:default] = attribute.default if attribute.default
  # properties[:collection] = true if attribute.collection?

  required_properties = ":#{attribute.name}, #{attribute.type}"
  required_properties += ", default: #{attribute.default.inspect}" if attribute.default
  required_properties += ", collection: #{attribute.collection}" if attribute.collection?
  required_properties += ", values: #{attribute.options['enum']}" if attribute.options["enum"]
  required_properties += ", pattern: /#{attribute.options['pattern']}/" if attribute.options["pattern"]
  required_properties += ", polymorphic: [#{attribute.polymorphic_classes.join(', ')}]" if attribute.polymorphic?

  required_properties
end

#close_namespaces(namespaces) ⇒ Object



10
11
12
# File 'lib/lutaml/model/schema/helpers/template_helper.rb', line 10

def close_namespaces(namespaces)
  namespaces.reverse.map { "end" }.join("\n")
end

#indent(level) ⇒ Object



14
15
16
# File 'lib/lutaml/model/schema/helpers/template_helper.rb', line 14

def indent(level)
  "  " * level
end

#open_namespaces(namespaces) ⇒ Object



6
7
8
# File 'lib/lutaml/model/schema/helpers/template_helper.rb', line 6

def open_namespaces(namespaces)
  namespaces.map { |ns| "module #{ns}" }.join("\n")
end