module HTTP::FormData
def create(data, encoder: nil)
-
(Urlencoded)
- otherwise -
(Multipart)
- if any of values is a {FormData::File}
Parameters:
-
data
(#to_h, Hash
) --
def create(data, encoder: nil) data = ensure_hash data if multipart?(data) Multipart.new(data) else Urlencoded.new(data, :encoder => encoder) end end
def ensure_hash(obj)
-
(Hash)
-
Raises:
-
(Error)
- `obj` can't be coerced.
Other tags:
- Note: - Internal usage helper, to workaround lack of `#to_h` on Ruby < 2.1
def ensure_hash(obj) case when obj.nil? then {} when obj.is_a?(Hash) then obj when obj.respond_to?(:to_h) then obj.to_h else raise Error, "#{obj.inspect} is neither Hash nor responds to :to_h" end end
def multipart?(data)
-
(Boolean)
-
Parameters:
-
data
(Hash
) --
def multipart?(data) data.any? do |_, v| next true if v.is_a? FormData::Part v.respond_to?(:to_ary) && v.to_ary.any? { |e| e.is_a? FormData::Part } end end