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.



9
10
11
12
13
# File 'lib/grape/validations/types/set_coercer.rb', line 9

def initialize(type, strict = false)
  super

  @coercer = nil
end

Instance Method Details

#call(value) ⇒ Object



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

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

  coerce_elements(value)
end