Skip to content

Instantly share code, notes, and snippets.

@toddsiegel
Created July 23, 2021 19:28
Show Gist options
  • Save toddsiegel/90d802809327564087da1f3122c231ae to your computer and use it in GitHub Desktop.
Save toddsiegel/90d802809327564087da1f3122c231ae to your computer and use it in GitHub Desktop.
Ruby and Rails Utiilities
# 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