Class: Restspec::Schema::Types::ArrayType

Inherits:
BasicType
  • Object
show all
Defined in:
lib/restspec/schema/types/array_type.rb

Instance Method Summary collapse

Methods inherited from BasicType

#initialize, #of, #totally_valid?, #|

Constructor Details

This class inherits a constructor from Restspec::Schema::Types::BasicType

Instance Method Details

#example_for(attribute) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/restspec/schema/types/array_type.rb', line 3

def example_for(attribute)
  length_only_works_with_parameterized_types!

  example_length.times.map do
    parameterized_type.example_for(attribute)
  end
end

#valid?(attribute, value) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
# File 'lib/restspec/schema/types/array_type.rb', line 11

def valid?(attribute, value)
  is_array = value.is_a?(Array)
  if parameterized_type
    is_array && value.all? do |item|
      parameterized_type.totally_valid?(attribute, item)
    end
  else
    is_array
  end
end