Attributes
bytesize | [R] |
Public Class methods
new(form)
[show source]
# File lib/httpx/transcoder/multipart/encoder.rb 8 def initialize(form) 9 @boundary = ("-" * 21) << SecureRandom.hex(21) 10 @part_index = 0 11 @buffer = "".b 12 13 @form = form 14 @parts = to_parts(form) 15 end
Public Instance methods
content_type()
[show source]
# File lib/httpx/transcoder/multipart/encoder.rb 17 def content_type 18 "multipart/form-data; boundary=#{@boundary}" 19 end
read(length = nil, outbuf = nil)
[show source]
# File lib/httpx/transcoder/multipart/encoder.rb 27 def read(length = nil, outbuf = nil) 28 data = String(outbuf).clear.force_encoding(Encoding::BINARY) if outbuf 29 data ||= "".b 30 31 read_chunks(data, length) 32 33 data unless length && data.empty? 34 end
rewind()
[show source]
# File lib/httpx/transcoder/multipart/encoder.rb 36 def rewind 37 form = @form.each_with_object([]) do |(key, val), aux| 38 if val.respond_to?(:path) && val.respond_to?(:reopen) && val.respond_to?(:closed?) && val.closed? 39 val = val.reopen(val.path, File::RDONLY) 40 end 41 val.rewind if val.respond_to?(:rewind) 42 aux << [key, val] 43 end 44 @form = form 45 @parts = to_parts(form) 46 @part_index = 0 47 end
to_s()
[show source]
# File lib/httpx/transcoder/multipart/encoder.rb 21 def to_s 22 read 23 ensure 24 rewind 25 end