Sha256: e18e4af04185e12d1505a2319f7aeeb0750fbc4694f021db000d89c53b8e7b11

Contents?: true

Size: 892 Bytes

Versions: 5

Compression:

Stored size: 892 Bytes

Contents

module Grape
  module Validations
    module Types
      # +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.
      class File < Virtus::Attribute
        def coerce(input)
          # Processing of multipart file objects
          # is already taken care of by Rack::Request.
          # Nothing to do here.
          input
        end

        def value_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
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.2.5/lib/grape/validations/types/file.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/lib/grape/validations/types/file.rb
grape-1.2.5 lib/grape/validations/types/file.rb
grape-1.2.4 lib/grape/validations/types/file.rb
grape-1.2.3 lib/grape/validations/types/file.rb