Class: Cocina::Generator::UnionType
- Inherits:
-
SchemaBase
- Object
- SchemaBase
- Cocina::Generator::UnionType
- Defined in:
- lib/cocina/generator/union_type.rb
Overview
Class for generating a union type
Instance Attribute Summary
Attributes inherited from SchemaBase
#key, #lite, #nullable, #parent, #relaxed, #required, #schema_doc, #schemas
Instance Method Summary collapse
Methods inherited from SchemaBase
#any_datatype?, #custom_type?, #datatype_from_doc_names, #datatype_from_doc_type, #defined_datatypes?, #deprecation, #description, #dry_datatype, #example, #filename, #initialize, #name, #optional, #preamble, #quote, #relaxed_comment, #string_dry_datatype, #to_multiline_comment
Constructor Details
This class inherits a constructor from Cocina::Generator::SchemaBase
Instance Method Details
#generate ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/cocina/generator/union_type.rb', line 7 def generate " # frozen_string_literal: true\n\n module Cocina\n module Models\n \#{preamble}\#{name} = \#{type_names}\n end\n end\n RUBY\nend\n" |
#type_names ⇒ Object
19 20 21 |
# File 'lib/cocina/generator/union_type.rb', line 19 def type_names schema_doc.one_of.map(&:name).join(' | ') end |