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

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

Overview

+Virtus::Attribute+ 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, and to prevent virtus from interfering.

Instance Method Summary collapse

Instance Method Details

#coerce(input) ⇒ Object


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

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

#value_coerced?(value) ⇒ Boolean

Returns:

  • (Boolean)

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

def value_coerced?(value)
  # Rack::Request creates a Hash with filename,
  # content type and an IO object. Grape wraps that
  # using hashie for convenience. Do a bit of basic
  # duck-typing.
  value.is_a?(Hashie::Mash) && value.key?(:tempfile)
end