Sha256: 199db3dcbfdeecccf37c84e767c918fd3ceffd646a4f1ca39e9380f98ea874b1

Contents?: true

Size: 664 Bytes

Versions: 21

Compression:

Stored size: 664 Bytes

Contents

# frozen_string_literal: true

module Cocina
  module Generator
    # Class for generating from an openapi schema
    class Datatype < SchemaBase
      def generate
        <<~RUBY
          # frozen_string_literal: true

          module Cocina
            module Models
              #{name} = Types::String#{pattern}#{enum}
            end
          end
        RUBY
      end

      def pattern
        return unless schema_doc.pattern

        ".constrained(format: /#{schema_doc.pattern}/)"
      end

      def enum
        return unless schema_doc.enum

        ".enum(#{schema_doc.enum.map { |item| quote(item) }.join(', ')})"
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
cocina-models-0.99.1 lib/cocina/generator/datatype.rb
cocina-models-0.99.0 lib/cocina/generator/datatype.rb
cocina-models-0.98.1 lib/cocina/generator/datatype.rb
cocina-models-0.98.0 lib/cocina/generator/datatype.rb
cocina-models-0.96.0 lib/cocina/generator/datatype.rb
cocina-models-0.95.1 lib/cocina/generator/datatype.rb
cocina-models-0.95.0 lib/cocina/generator/datatype.rb
cocina-models-0.94.2 lib/cocina/generator/datatype.rb
cocina-models-0.94.1 lib/cocina/generator/datatype.rb
cocina-models-0.94.0 lib/cocina/generator/datatype.rb
cocina-models-0.93.1 lib/cocina/generator/datatype.rb
cocina-models-0.93.0 lib/cocina/generator/datatype.rb
cocina-models-0.92.0 lib/cocina/generator/datatype.rb
cocina-models-0.91.4 lib/cocina/generator/datatype.rb
cocina-models-0.91.3 lib/cocina/generator/datatype.rb
cocina-models-0.91.2 lib/cocina/generator/datatype.rb
cocina-models-0.91.1 lib/cocina/generator/datatype.rb
cocina-models-0.91.0 lib/cocina/generator/datatype.rb
cocina-models-0.90.0 lib/cocina/generator/datatype.rb
cocina-models-0.89.1 lib/cocina/generator/datatype.rb