<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>Martian Intuition - of Mogrify, Ruby Tempfile &amp; Dynamic Class Definitions Comments</title>
  <id>tag:www.marsorange.com,2010:/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions/comments</id>
  <generator uri="http://mephistoblog.com" version="0.8.0">Mephisto Drax</generator>
  <link href="http://www.marsorange.com/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions/comments.xml" rel="self" type="application/atom+xml"/>
  <link href="/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions" rel="alternate" type="text/html"/>
  <updated>2009-08-08T18:21:00Z</updated>
  <entry xml:base="http://www.marsorange.com/">
    <author>
      <name>silverdr</name>
    </author>
    <id>tag:www.marsorange.com,2006-07-17:72:9155</id>
    <published>2009-08-08T18:21:00Z</published>
    <updated>2009-08-08T18:21:00Z</updated>
    <category term="Work"/>
    <link href="http://www.marsorange.com/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions" rel="alternate" type="text/html"/>
    <title>Comment on 'of Mogrify, Ruby Tempfile &amp; Dynamic Class Definitions' by silverdr</title>
<content type="html">&lt;p&gt;Steve - thanks. Simple solution to my problem.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://www.marsorange.com/">
    <author>
      <name>Matt</name>
    </author>
    <id>tag:www.marsorange.com,2006-07-17:72:1288</id>
    <published>2008-04-28T16:57:28Z</published>
    <updated>2008-04-28T16:57:28Z</updated>
    <category term="Work"/>
    <link href="http://www.marsorange.com/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions" rel="alternate" type="text/html"/>
    <title>Comment on 'of Mogrify, Ruby Tempfile &amp; Dynamic Class Definitions' by Matt</title>
<content type="html">&lt;p&gt;Do you know if the newest version fixes this?
== 1.2.2 / 2007-06-01&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://www.marsorange.com/">
    <author>
      <name>Steve</name>
    </author>
    <id>tag:www.marsorange.com,2006-07-17:72:94</id>
    <published>2007-07-15T17:48:23Z</published>
    <updated>2007-07-15T17:48:23Z</updated>
    <category term="Work"/>
    <link href="http://www.marsorange.com/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions" rel="alternate" type="text/html"/>
    <title>Comment on 'of Mogrify, Ruby Tempfile &amp; Dynamic Class Definitions' by Steve</title>
<content type="html">I had the same exact problem and extended your idea a little. This modification to make_tmpname allows you to create temp files with whatever extension you like (but if you don't specify an extension, it works like normal):
&lt;pre&gt;
Module MiniMagick
  class ImgTempFile &amp;lt; Tempfile
    def make_tmpname(basename, n)
      # force tempfile to use basename's extension if provided
      ext = File::extname(basename)
      # force hyphens instead of periods in name
      sprintf('%s%d-%d%s', File::basename(basename, ext), $$, n, ext)
    end
  end # class
end # module
&lt;/pre&gt;

Also, I chose to subclass Tempfile rather than overwrite, which required a small alteration to mini_magick.rb:
&lt;pre&gt;
          tmp = ImgTempFile.new(&quot;minimagic&quot;)
&lt;/pre&gt;
Finally, here's a short test that shows it's working (put it in any convenient test file that gets run on related stuff):
&lt;pre&gt;
  def test_image_temp_file
    tmp = MiniMagick::ImgTempFile.new('test')
    assert_match %r{^test}, File::basename(tmp.path)
    tmp = MiniMagick::ImgTempFile.new('test.jpg')
    assert_match %r{^test}, File::basename(tmp.path)
    assert_match %r{\.jpg$}, File::basename(tmp.path)
  end
&lt;/pre&gt;</content>  </entry>
  <entry xml:base="http://www.marsorange.com/">
    <author>
      <name>mzpn</name>
    </author>
    <id>tag:www.marsorange.com,2006-07-17:72:93</id>
    <published>2007-07-15T17:48:23Z</published>
    <updated>2007-07-15T17:48:23Z</updated>
    <category term="Work"/>
    <link href="http://www.marsorange.com/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions" rel="alternate" type="text/html"/>
    <title>Comment on 'of Mogrify, Ruby Tempfile &amp; Dynamic Class Definitions' by mzpn</title>
<content type="html">fun</content>  </entry>
</feed>
