class Grape::Validations::Types::SetCoercer
Takes the given array and converts it to a set. Every element of the set is also coerced.
Public Class Methods
new(type, strict = false)
click to toggle source
Calls superclass method
Grape::Validations::Types::ArrayCoercer::new
# File lib/grape/validations/types/set_coercer.rb, line 14 def initialize(type, strict = false) super @coercer = nil end
Public Instance Methods
call(value)
click to toggle source
# 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
Protected Instance Methods
coerce_elements(collection)
click to toggle source
# File lib/grape/validations/types/set_coercer.rb, line 28 def coerce_elements(collection) collection.each_with_object(Set.new) do |elem, memo| coerced_elem = elem_coercer.call(elem) return coerced_elem if coerced_elem.is_a?(InvalidValue) memo.add(coerced_elem) end end