Sha256: f5fd39d1748e42353fefd4be1e79a2c0dd0451dfe8e2a87d56189d23e1578fe4

Contents?: true

Size: 789 Bytes

Versions: 6

Compression:

Stored size: 789 Bytes

Contents

######################################################################
#
# Alternative to the standard ruby tempfile library, which lets you
# specify a filename suffix.
#
######################################################################

require 'delegate'
require 'tmpdir'
require 'tempfile'

#
# Setting the extension of a temp file has only been possible since
# Ruby 1.8.7.
#
module C
  if RUBY_VERSION >= '1.8.7'
    Tempfile = ::Tempfile
  else
    class Tempfile < ::Tempfile
      def initialize(basename, tmpdir=Dir::tmpdir)
        if basename.is_a?(::Array)
          basename, @suffix = *basename
        end
        super(basename, tmpdir)
      end

      def make_tmpname(basename, n)
        sprintf('%s%d.%d%s', basename, $$, n, @suffix)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
cast-0.3.1 lib/cast/tempfile.rb
cast-0.3.0 lib/cast/tempfile.rb
casty-0.3.2 lib/casty/tempfile.rb
casty-0.3.1 lib/casty/tempfile.rb
cast-0.2.1 lib/cast/tempfile.rb
cast-0.2.0 lib/cast/tempfile.rb