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, register_collection

Constructor Details

#initialize(type, strict = false) ⇒ SetCoercer

Returns a new instance of SetCoercer.


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

def initialize(type, strict = false)
  super

  @coercer = nil
end

Instance Method Details

#call(value) ⇒ Object


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

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

  coerce_elements(value)
end