Class: Cocina::Generator::Datatype

Inherits:
SchemaBase show all
Defined in:
lib/cocina/generator/datatype.rb

Overview

Class for generating from an openapi schema

Instance Attribute Summary

Attributes inherited from SchemaBase

#key, #nullable, #parent, #relaxed, #required, #schema_doc

Instance Method Summary collapse

Methods inherited from SchemaBase

#any_datatype?, #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
18
19
# File 'lib/cocina/generator/datatype.rb', line 7

def generate
  "    # frozen_string_literal: true\n\n    module Cocina\n      module Models\n        \#{name} = Types::String.constrained(\n          format: /\#{schema_doc.pattern}/i\n        )\n      end\n    end\n  RUBY\nend\n"