Class: Cocina::Generator::UnionType

Inherits:
SchemaBase show all
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

Constructor Details

This class inherits a constructor from Cocina::Generator::SchemaBase

Instance Method Details

#generateObject



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/cocina/generator/union_type.rb', line 7

def generate
  <<~RUBY
    # frozen_string_literal: true

    module Cocina
      module Models
        #{name} = #{type_names}
      end
    end
  RUBY
end

#type_namesObject



19
20
21
# File 'lib/cocina/generator/union_type.rb', line 19

def type_names
  schema_doc.one_of.map(&:name).join(' | ')
end