Sha256: 02d213bcd33e90c63b71e7cb850bedae7c5c4fb059351e38a1ab33d76c2faec8
Contents?: true
Size: 1.24 KB
Versions: 2
Compression:
Stored size: 1.24 KB
Contents
module Typhoeus class ParamProcessor class << self def traverse_params_hash(hash, result = nil, current_key = nil) result ||= { :files => [], :params => [] } hash.keys.sort { |a, b| a.to_s <=> b.to_s }.collect do |key| new_key = (current_key ? "#{current_key}[#{key}]" : key).to_s current_value = hash[key] process_value current_value, :result => result, :new_key => new_key end result end def process_value(current_value, options) result = options[:result] new_key = options[:new_key] case current_value when Hash traverse_params_hash(current_value, result, new_key) when Array current_value.each do |v| result[:params] << [new_key, v.to_s] end when File, Tempfile filename = File.basename(current_value.path) types = MIME::Types.type_for(filename) result[:files] << [ new_key, filename, types.empty? ? 'application/octet-stream' : types[0].to_s, File.expand_path(current_value.path) ] else result[:params] << [new_key, current_value.to_s] end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
marnen-typhoeus-0.3.7 | lib/typhoeus/param_processor.rb |
marnen-typhoeus-0.3.6 | lib/typhoeus/param_processor.rb |