lib/grape/validations/validators/coerce.rb in grape-0.11.0 vs lib/grape/validations/validators/coerce.rb in grape-0.12.0

- old
+ new

@@ -30,29 +30,30 @@ return true if val.nil? if klass == Virtus::Attribute::Boolean val.is_a?(TrueClass) || val.is_a?(FalseClass) || (val.is_a?(String) && val.empty?) elsif klass == Rack::Multipart::UploadedFile val.is_a?(Hashie::Mash) && val.key?(:tempfile) - elsif [DateTime, Date, Numeric].any?{ |vclass| vclass >= klass } + elsif [DateTime, Date, Numeric].any? { |vclass| vclass >= klass } return true if val.is_a?(String) && val.empty? val.is_a?(klass) else val.is_a?(klass) end end def valid_type?(val) - if @option.is_a?(Array) - _valid_array_type?(@option[0], val) + if @option.is_a?(Array) || @option.is_a?(Set) + _valid_array_type?(@option.first, val) else _valid_single_type?(@option, val) end end def coerce_value(type, val) # Don't coerce things other than nil to Arrays or Hashes - return val || [] if type == Array - return val || {} if type == Hash + return val || [] if type == Array + return val || Set.new if type == Set + return val || {} if type == Hash converter = Virtus::Attribute.build(type) converter.coerce(val) # not the prettiest but some invalid coercion can currently trigger