Sha256: 3a30e393ac610b9f6b00bdc085976914b28d1f4d33c0bf776189e0ed42c880e0

Contents?: true

Size: 550 Bytes

Versions: 40

Compression:

Stored size: 550 Bytes

Contents

# frozen_string_literal: true

module Cocina
  module Generator
    # Class for generating from an openapi array
    class SchemaArray < SchemaBase
      def generate
        "attribute :#{name.camelize(:lower)}, Types::Strict::Array.of(#{array_of_type})#{omittable}"
      end

      def omittable
        if required
          '.default([].freeze)'
        else
          '.meta(omittable: true)'
        end
      end

      def array_of_type
        schema_doc.items.name || "Types::#{dry_datatype(schema_doc.items)}"
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
cocina-models-0.46.0 lib/cocina/generator/schema_array.rb
cocina-models-0.45.0 lib/cocina/generator/schema_array.rb
cocina-models-0.44.0 lib/cocina/generator/schema_array.rb
cocina-models-0.43.0 lib/cocina/generator/schema_array.rb
cocina-models-0.42.1 lib/cocina/generator/schema_array.rb
cocina-models-0.42.0 lib/cocina/generator/schema_array.rb
cocina-models-0.41.0 lib/cocina/generator/schema_array.rb
cocina-models-0.40.1 lib/cocina/generator/schema_array.rb
cocina-models-0.40.0 lib/cocina/generator/schema_array.rb
cocina-models-0.39.0 lib/cocina/generator/schema_array.rb
cocina-models-0.38.0 lib/cocina/generator/schema_array.rb
cocina-models-0.37.0 lib/cocina/generator/schema_array.rb
cocina-models-0.36.0 lib/cocina/generator/schema_array.rb
cocina-models-0.35.0 lib/cocina/generator/schema_array.rb
cocina-models-0.34.1 lib/cocina/generator/schema_array.rb
cocina-models-0.34.0 lib/cocina/generator/schema_array.rb
cocina-models-0.33.0 lib/cocina/generator/schema_array.rb
cocina-models-0.32.0 lib/cocina/generator/schema_array.rb
cocina-models-0.31.1 lib/cocina/generator/schema_array.rb
cocina-models-0.31.0 lib/cocina/generator/schema_array.rb