Skip to content

Commit 5a79261

Browse files
author
Matt Kelly
committed
Handle Hash vs Array of pairs parts
1 parent 77f70d7 commit 5a79261

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

lib/http/form_data/multipart.rb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ class Multipart
1616

1717
# @param [#to_h, Hash] data form data key-value Hash
1818
def initialize(data, boundary: self.class.generate_boundary)
19-
parts = Param.coerce FormData.ensure_hash data unless @params.is_a?(Array)
20-
2119
@boundary = boundary.to_s.freeze
22-
@io = CompositeIO.new [*parts.flat_map { |part| [glue, part] }, tail]
20+
@io = CompositeIO.new [*parts(data).flat_map { |part| [glue, part] }, tail]
2321
end
2422

2523
# Generates a string suitable for using as a boundary in multipart form
@@ -55,12 +53,9 @@ def tail
5553
@tail ||= "--#{@boundary}--#{CRLF}"
5654
end
5755

58-
def join_multipart_pairs(pairs)
59-
pairs.each_cons(2).each do |pair|
60-
multipart = pair.first
61-
file = pair.last
62-
63-
end
56+
def parts(data)
57+
return Param.coerce FormData.ensure_hash data if @params.is_a?(Hash)
58+
Param.coerce_array_of_pairs data
6459
end
6560
end
6661
end

0 commit comments

Comments
 (0)