class Grape::Validations::Types::VariantCollectionCoercer

that allow members of more than one type.
This class wraps {MultipleTypeCoercer}, for use with collections

def call(value)

Returns:
  • (Array, Set, InvalidValue) -
    Parameters:
    • value (Array) -- collection of values to be coerced
    def call(value)
      return unless value.is_a? Array
      value =
        if @method
          @method.call(value)
        else
          value.map { |v| @member_coercer.call(v) }
        end
      return Set.new value if @types.is_a? Set
      value
    end

    def initialize(types, method = nil)

    Parameters:
    • method (#call, #parse) -- method by which values should be coerced
    • types (Array, Set) -- list of allowed types,
    def initialize(types, method = nil)
      @types = types
      @method = method.respond_to?(:parse) ? method.method(:parse) : method
      # If we have a coercion method, pass it in here to save
      # building another one, even though we call it directly.
      @member_coercer = MultipleTypeCoercer.new types, method
    end