Sha256: 98b377fa91a5d82d1e3063e57e0d69a0fd961e0865bf66ad39760cf6bd85fe0f

Contents?: true

Size: 823 Bytes

Versions: 3

Compression:

Stored size: 823 Bytes

Contents

# Abstract base class for List types (arrays in OpenAPI terms).
# Unlike other types, this one should not be manually inherited from,
# but is used indirectly via `array_of: SomeType`.
class Taro::Types::ListType < Taro::Types::BaseType
  extend Taro::Types::Shared::ItemType

  self.openapi_type = :array

  def coerce_input
    object.instance_of?(Array) || input_error('must be an Array')

    item_type = self.class.item_type
    object.map { |el| item_type.new(el).coerce_input }
  end

  def coerce_response
    object.respond_to?(:map) || response_error('must be an Enumerable')

    item_type = self.class.item_type
    object.map { |el| item_type.new(el).coerce_response }
  end

  def self.default_openapi_name
    "#{item_type.openapi_name}_List"
  end

  define_derived_type :array, 'Taro::Types::ListType'
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
taro-1.4.0 lib/taro/types/list_type.rb
taro-1.3.0 lib/taro/types/list_type.rb
taro-1.2.0 lib/taro/types/list_type.rb