Class: Restspec::Schema::Types::OneOfType
- Defined in:
- lib/restspec/schema/types/one_of_type.rb
Overview
It will return an element of a set of elements while making a example and checks against that same set of element while validating. The following options are needed:
elements: An array of the element to use
@example: attribute :pet_type, one_of(elements: %wcat)
Instance Method Summary collapse
-
#example_for(attribute) ⇒ Object
A sample of the elements array.
- #to_s ⇒ Object
-
#valid?(attribute, value) ⇒ true, false
If the value is included in the elements.
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
Returns A sample of the elements array.
16 17 18 |
# File 'lib/restspec/schema/types/one_of_type.rb', line 16 def example_for(attribute) elements.sample end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/restspec/schema/types/one_of_type.rb', line 29 def to_s "OneOfType(#{elements})" end |
#valid?(attribute, value) ⇒ true, false
Returns If the value is included in the elements.
25 26 27 |
# File 'lib/restspec/schema/types/one_of_type.rb', line 25 def valid?(attribute, value) elements.include?(value) end |