| Class | Grape::Validations::Types::MultipleTypeCoercer |
| In: |
lib/grape/validations/types/multiple_type_coercer.rb
|
| Parent: | Object |
This class is intended for use with Grape endpoint parameters that have been declared to be of variant-type using the +:types+ option. MultipleTypeCoercer will build a coercer for each type declared in the array passed to +:types+ using {Types.build_coercer}. It will apply these coercers to parameter values in the order given to +:types+, and will return the value returned by the first coercer to successfully coerce the parameter value. Therefore if String is an allowed type it should be declared last, since it will always successfully "coerce" the value.
This method is called from somewhere within +Virtus::Attribute::coerce+ in order to coerce the given value.
@param value [String] value to be coerced, in grape
this should always be a string.
@return [Object,InvalidValue] the coerced result, or an instance
of {InvalidValue} if the value could not be coerced.
This method is called from somewhere within +Virtus::Attribute::value_coerced?+ in order to assert that the value has been coerced successfully. Due to Grape‘s design this will in fact only be called if a custom coercion method is being used, since {call} returns an {InvalidValue} object if the value could not be coerced.
@param _primitive [Axiom::Types::Type] primitive type
for the coercion as detected by axiom-types' inference system. For custom types this is typically not much use (i.e. it is +Axiom::Types::Object+) unless special inference rules have been declared for the type.
@param value [Object] a coerced result returned from {call} @return [true,false] whether or not the coerced value
satisfies type requirements.