Class: Cocina::Generator::Datatype
- Inherits:
-
SchemaBase
- Object
- SchemaBase
- Cocina::Generator::Datatype
- Defined in:
- lib/cocina/generator/datatype.rb
Overview
Class for generating from an openapi schema
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
#enum ⇒ Object
25 26 27 28 29 |
# File 'lib/cocina/generator/datatype.rb', line 25 def enum return unless schema_doc.enum ".enum(#{schema_doc.enum.map { |item| quote(item) }.join(', ')})" end |
#generate ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/cocina/generator/datatype.rb', line 7 def generate <<~RUBY # frozen_string_literal: true module Cocina module Models #{name} = Types::String#{pattern}#{enum} end end RUBY end |
#pattern ⇒ Object
19 20 21 22 23 |
# File 'lib/cocina/generator/datatype.rb', line 19 def pattern return unless schema_doc.pattern ".constrained(format: /#{schema_doc.pattern}/)" end |