Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filename mimetype overrides #145

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Gemfile.lock
.yardoc
doc
coverage
.idea
26 changes: 20 additions & 6 deletions lib/ethon/easy/queryable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,30 @@ def encode_rack_array_pairs(h, prefix, pairs)
end
end

def encode_multi_array_pairs(h, prefix, pairs)
h.each_with_index do |v, i|
key = prefix
pairs_for(v, key, pairs)
def encode_multi_array_pairs(h, prefix, pairs)
h.each_with_index do |v, i|
key = prefix
pairs_for(v, key, pairs)
end
end
end

def pairs_for(v, key, pairs)
case v
when Hash, Array
when Hash

# If the hash element contains an entry named "filehandle" then we
# have a file with a potentially specified filename and mimetype.
# handle this special case.
if !v[:filehandle].nil? and v[:filehandle].is_a? File
fileinfo = file_info(v[:filehandle])

if !v[:filename].nil? then fileinfo[0] = v[:filename] end
if !v[:mimetype].nil? then fileinfo[1] = v[:mimetype] end
pairs << [key, fileinfo]
else
recursively_generate_pairs(v, key, pairs)
end
when Array
recursively_generate_pairs(v, key, pairs)
when File, Tempfile
pairs << [key, file_info(v)]
Expand Down