Created
July 23, 2021 19:28
-
-
Save toddsiegel/90d802809327564087da1f3122c231ae to your computer and use it in GitHub Desktop.
Ruby and Rails Utiilities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
module UsesTempfile | |
def with_tempfile(name: 'temp-zip-file', temp_dir: Rails.root.join('tmp').to_s, binmode: false) | |
tempfile = Tempfile.new('temp-zip-file', temp_dir) | |
tempfile.binmode if binmode | |
yield tempfile | |
ensure | |
tempfile.close | |
tempfile.unlink | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment