Module: HTTPX::Transcoder::Multipart::Part

Defined in:
lib/httpx/transcoder/multipart/part.rb,
sig/transcoder/multipart.rbs

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(value) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/httpx/transcoder/multipart/part.rb', line 8

def call(value)
  # take out specialized objects of the way
  if value.respond_to?(:filename) && value.respond_to?(:content_type) && value.respond_to?(:read)
    return value, value.content_type, value.filename
  end

  content_type = filename = nil

  if value.is_a?(Hash)
    content_type = value[:content_type]
    filename = value[:filename]
    value = value[:body]
  end

  value = value.open(File::RDONLY, encoding: Encoding::BINARY) if Object.const_defined?(:Pathname) && value.is_a?(Pathname)

  if value.respond_to?(:path) && value.respond_to?(:read)
    # either a File, a Tempfile, or something else which has to quack like a file
    filename ||= File.basename(value.path)
    content_type ||= MimeTypeDetector.call(value, filename) || "application/octet-stream"
    [value, content_type, filename]
  else
    [StringIO.new(value.to_s), content_type || "text/plain", filename]
  end
end

Instance Method Details

#self?void #self?[StringIO, String, String?], [File | Tempfile, String, String]

Overloads:

  • #self?void

    This method returns an undefined value.

  • #self?[StringIO, String, String?], [File | Tempfile, String, String]

    Parameters:

    • value (multipart_nested_value)

    Returns:

    • ([StringIO, String, String?], [File | Tempfile, String, String])


97
98
# File 'sig/transcoder/multipart.rbs', line 97

def self?.call: [U] (Object & _MultipartInput multipart_input) -> [U, String, String]
| (multipart_nested_value value) -> ([StringIO, String, String?] | [File | Tempfile, String, String])