module Grape::Formats
Scaffolding for building types.
Contains collections of constants that may be passed as the type
parameter of {Grape::Dsl::Parameters#requires} or {Grape::Dsl::Parameters#optional}, providing parameter coercion from a range of standard formats to a number of standard types.
Constants
- VERSION
Current version of the grape-formats gem
Public Class Methods
build(type, method)
click to toggle source
Common function for building 'types' that consist of an underlying primitive type and an arbitrary coercion method used to convert strings to that type.
Makes use of the CustomTypeCoercer
class in the base Grape
gem.
@param type [Class] the type to which parameter values will be coerced @param method [Proc] type coercion method.
Should accept a single +String+ parameter and return an object of type +type+.
@return [Virtus::Attribute] an object that may be passed as the type
option for any Grape endpoint parameter declared with +requires+ or +optional+.
# File lib/grape/formats/build.rb, line 20 def self.build(type, method) Grape::Validations::Types::CustomTypeCoercer.build(type, method) end