Skip to content

Instantly share code, notes, and snippets.

@alpaca-tc
Created October 29, 2014 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alpaca-tc/b06a1d1265d0d4c096fa to your computer and use it in GitHub Desktop.
Save alpaca-tc/b06a1d1265d0d4c096fa to your computer and use it in GitHub Desktop.
module CarrierWave
module Uploader
module RiakOpenable
# When using riak, we can not access to file directory.
# RiakOpenable#open provide tempfile which contains copy from server.
def open(*args)
options = args.extract_options!
file_opts = options.merge(binmode: true)
extname = File.extname(filename)
filename_option = [File.basename(filename, extname), extname]
tempfile = Tempfile.new(filename_option, file_opts)
tempfile.write(read)
if block_given?
begin
yield(tempfile)
rescue => e
tempfile.close!
end
else
tempfile
end
end
end
end
e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment