Skip to content

Instantly share code, notes, and snippets.

@imajes
Created November 10, 2011 18:16
Show Gist options
  • Save imajes/1355625 to your computer and use it in GitHub Desktop.
Save imajes/1355625 to your computer and use it in GitHub Desktop.
class Foo
has_one :image
def process_stuff
img = Image.first
img.with_temp_file('/path/to/tmpfile') do |tf|
tf.rotate
tf.bounce
tf.other_thing
img.save(:file => tf)
end
end
end
class Image
belongs_to :foo
def with_temp_file(path, &block)
# download content, put it into a local fle
tf = open(path, 'wb') { |fh|
fh.write(downloaded_content)
yield
}
tf.delete
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment