Class: Grape::Validations::Types::SetCoercer

Inherits:
DryTypeCoercer show all
Defined in:
lib/grape/validations/types/set_coercer.rb

Overview

Takes the given array and converts it to a set. Every element of the set is also coerced.

Instance Method Summary collapse

Constructor Details

#initialize(type, strict = false) ⇒ SetCoercer

Returns a new instance of SetCoercer.



12
13
14
15
16
# File 'lib/grape/validations/types/set_coercer.rb', line 12

def initialize(type, strict = false)
  super

  @elem_coercer = PrimitiveCoercer.new(type.first, strict)
end

Instance Method Details

#call(value) ⇒ Object



18
19
20
21
22
# File 'lib/grape/validations/types/set_coercer.rb', line 18

def call(value)
  return InvalidValue.new unless value.is_a?(Array)

  coerce_elements(value)
end