class Grape::Validations::Types::CustomTypeCoercer

This class will detect type classes that implement a class-level parse method. The method should accept one String argument and should return the value coerced to the appropriate type. The method may raise an exception if there are any problems parsing the string.

Alternately an optional method may be supplied (see the coerce_with option of {Grape::Dsl::Parameters#requires}). This may be any class or object implementing parse or call, with the same contract as described above.

Type Checking


Calls to coerced? will consult this class to check that the coerced value produced above is in fact of the expected type. By default this class performs a basic check against the type supplied, but this behaviour will be overridden if the class implements a class-level coerced? or parsed? method. This method will receive a single parameter that is the coerced value and should return true if the value meets type expectations. Arbitrary assertions may be made here but the grape validation system should be preferred.

Alternately a proc or other object responding to call may be supplied in place of a type. This should implement the same contract as coerced?, and must be supplied with a coercion method.