Class: Taro::Types::ListType

Inherits:
BaseType
  • Object
show all
Extended by:
Shared::ItemType
Defined in:
lib/taro/types/list_type.rb

Overview

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`.

Instance Attribute Summary

Attributes included from Shared::ItemType

#item_type

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Shared::ItemType

raise_mixed_types

Class Method Details

.default_openapi_nameObject



23
24
25
# File 'lib/taro/types/list_type.rb', line 23

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

Instance Method Details

#coerce_inputObject



9
10
11
12
13
14
# File 'lib/taro/types/list_type.rb', line 9

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

#coerce_responseObject



16
17
18
19
20
21
# File 'lib/taro/types/list_type.rb', line 16

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