Sha256: 3649e8c3cb94ea8f43eb3cd468a06e81ab95632afde59605df029944e697770a

Contents?: true

Size: 961 Bytes

Versions: 20

Compression:

Stored size: 961 Bytes

Contents

# frozen_string_literal: true

module Grape
  module Validations
    module Types
      # 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.
      class File
        class << self
          def parse(input)
            return if input.nil?
            return InvalidValue.new unless parsed?(input)

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

          def parsed?(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
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
grape-2.2.0 lib/grape/validations/types/file.rb
grape-2.1.3 lib/grape/validations/types/file.rb
grape-2.1.2 lib/grape/validations/types/file.rb
grape-2.1.1 lib/grape/validations/types/file.rb
grape-2.1.0 lib/grape/validations/types/file.rb
grape-2.0.0 lib/grape/validations/types/file.rb
grape-1.8.0 lib/grape/validations/types/file.rb
grape-1.7.1 lib/grape/validations/types/file.rb
grape-1.7.0 lib/grape/validations/types/file.rb
grape-1.6.2 lib/grape/validations/types/file.rb
grape-1.6.1 lib/grape/validations/types/file.rb
grape-1.6.0 lib/grape/validations/types/file.rb
grape-1.5.3 lib/grape/validations/types/file.rb
grape-1.5.2 lib/grape/validations/types/file.rb
grape-1.5.1 lib/grape/validations/types/file.rb
grape-1.5.0 lib/grape/validations/types/file.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.4.0/lib/grape/validations/types/file.rb
grape-1.4.0 lib/grape/validations/types/file.rb
grape-1.3.3 lib/grape/validations/types/file.rb
grape-1.3.2 lib/grape/validations/types/file.rb