Public Instance methods
call(value)
[show source]
# File lib/httpx/transcoder/multipart/part.rb 8 def call(value) 9 # take out specialized objects of the way 10 if value.respond_to?(:filename) && value.respond_to?(:content_type) && value.respond_to?(:read) 11 return value, value.content_type, value.filename 12 end 13 14 content_type = filename = nil 15 16 if value.is_a?(Hash) 17 content_type = value[:content_type] 18 filename = value[:filename] 19 value = value[:body] 20 end 21 22 value = value.open(File::RDONLY) if Object.const_defined?(:Pathname) && value.is_a?(Pathname) 23 24 if value.respond_to?(:path) && value.respond_to?(:read) 25 # either a File, a Tempfile, or something else which has to quack like a file 26 filename ||= File.basename(value.path) 27 content_type ||= MimeTypeDetector.call(value, filename) || "application/octet-stream" 28 [value, content_type, filename] 29 else 30 [StringIO.new(value.to_s), content_type || "text/plain", filename] 31 end 32 end