Skip to content

Commit b721815

Browse files
Don't care for nil for all parameters.
1 parent 0d14cd8 commit b721815

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/grape/validations/coerce.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ def _valid_array_type?(type, values)
2626
end
2727

2828
def _valid_single_type?(klass, val)
29+
# allow nil, to ignore when a parameter is absent
30+
return true if val.nil?
2931
if klass == Virtus::Attribute::Boolean
3032
val.is_a?(TrueClass) || val.is_a?(FalseClass)
3133
elsif klass == Rack::Multipart::UploadedFile
3234
val.is_a?(Hashie::Mash) && val.key?(:tempfile)
3335
else
34-
# allow nil, to ignore when a parameter is absent
35-
val.nil? || val.is_a?(klass)
36+
val.is_a?(klass)
3637
end
3738
end
3839

0 commit comments

Comments
 (0)