Class: Restspec::Schema::Types::ArrayType
- Defined in:
- lib/restspec/schema/types/array_type.rb
Instance Method Summary collapse
-
#example_for(attribute) ⇒ Array
Generates an example array.
-
#valid?(attribute, value) ⇒ true, false
Validates if the array is valid.
Methods inherited from BasicType
#initialize, #of, #to_s, #totally_valid?, #|
Constructor Details
This class inherits a constructor from Restspec::Schema::Types::BasicType
Instance Method Details
#example_for(attribute) ⇒ Array
Generates an example array.
29 30 31 32 33 34 35 |
# File 'lib/restspec/schema/types/array_type.rb', line 29 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) ⇒ true, false
Validates if the array is valid.
- Without a parameterized type, it only checks if the value is an array.
- With a parameterized type, it checks is every object inside the array is valid against the parameterized type.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/restspec/schema/types/array_type.rb', line 47 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 |