class Restspec::Schema::Types::OneOfType
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: %w{dog cat})
Public Instance Methods
example_for(attribute)
click to toggle source
@param attribute [Restspec::Schema::Attribute] the atribute of the schema.
@return [Object] A sample of the elements array. @raise KeyError if the elements option was not initialized.
# File lib/restspec/schema/types/one_of_type.rb, line 16 def example_for(attribute) elements.sample end
to_s()
click to toggle source
# File lib/restspec/schema/types/one_of_type.rb, line 29 def to_s "OneOfType(#{elements})" end
valid?(attribute, value)
click to toggle source
@param attribute [Restspec::Schema::Attribute] the atribute of the schema. @param value [Object] the value of the attribute.
@return [true, false] If the value is included in the elements. @raise KeyError if the elements option was not initialized.
# File lib/restspec/schema/types/one_of_type.rb, line 25 def valid?(attribute, value) elements.include?(value) end
Private Instance Methods
elements()
click to toggle source
# File lib/restspec/schema/types/one_of_type.rb, line 35 def elements options.fetch(:elements) end