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

Inherits:
ArrayCoercer 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

Methods inherited from DryTypeCoercer

coercer_instance_for, collection_coercer_for

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

  @coercer = nil
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