Class: Grape::Validations::Types::File

Inherits:
Object
  • Object
show all
Defined in:
lib/grape/validations/types/file.rb

Overview

Implementation for parameters that are multipart file objects. Actual handling of these objects is provided by Rack::Request; this class is here only to assert that rack’s handling has succeeded.

Instance Method Summary collapse

Instance Method Details

#call(input) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/grape/validations/types/file.rb', line 10

def call(input)
  return InvalidValue.new unless coerced?(input)

  # Processing of multipart file objects
  # is already taken care of by Rack::Request.
  # Nothing to do here.
  input
end

#coerced?(value) ⇒ Boolean

Returns:

  • (Boolean)


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

def coerced?(value)
  # Rack::Request creates a Hash with filename,
  # content type and an IO object. Do a bit of basic
  # duck-typing.
  value.is_a?(::Hash) && value.key?(:tempfile) && value[:tempfile].is_a?(Tempfile)
end