Module: HTTPX::Transcoder::Multipart

Defined in:
lib/httpx/transcoder/multipart.rb,
lib/httpx/transcoder/multipart/part.rb,
lib/httpx/transcoder/multipart/decoder.rb,
lib/httpx/transcoder/multipart/encoder.rb,
lib/httpx/transcoder/multipart/mime_type_detector.rb

Defined Under Namespace

Modules: MimeTypeDetector, Part Classes: Decoder, Encoder, FilePart

Constant Summary collapse

MULTIPART_VALUE_COND =
lambda do |value|
  value.respond_to?(:read) ||
    (value.respond_to?(:to_hash) &&
      value.key?(:body) &&
      (value.key?(:filename) || value.key?(:content_type)))
end

Class Method Summary collapse

Class Method Details

.encode(form_data) ⇒ Object



27
28
29
# File 'lib/httpx/transcoder/multipart.rb', line 27

def encode(form_data)
  Encoder.new(form_data)
end

.multipart?(form_data) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
# File 'lib/httpx/transcoder/multipart.rb', line 19

def multipart?(form_data)
  form_data.any? do |_, v|
    Multipart::MULTIPART_VALUE_COND.call(v) ||
      (v.respond_to?(:to_ary) && v.to_ary.any?(&Multipart::MULTIPART_VALUE_COND)) ||
      (v.respond_to?(:to_hash) && v.to_hash.any? { |_, e| Multipart::MULTIPART_VALUE_COND.call(e) })
  end
end